github.com/vtorhonen/terraform@v0.9.0-beta2.0.20170307220345-5d894e4ffda7/website/source/docs/providers/aws/r/lambda_function.html.markdown (about)

     1  ---
     2  layout: "aws"
     3  page_title: "AWS: aws_lambda_function"
     4  sidebar_current: "docs-aws-resource-lambda-function"
     5  description: |-
     6    Provides a Lambda Function resource. Lambda allows you to trigger execution of code in response to events in AWS. The Lambda Function itself includes source code and runtime configuration.
     7  ---
     8  
     9  # aws\_lambda\_function
    10  
    11  Provides a Lambda Function resource. Lambda allows you to trigger execution of code in response to events in AWS. The Lambda Function itself includes source code and runtime configuration.
    12  
    13  For information about Lambda and how to use it, see [What is AWS Lambda?][1]
    14  
    15  ## Example Usage
    16  
    17  ```
    18  resource "aws_iam_role" "iam_for_lambda" {
    19    name = "iam_for_lambda"
    20  
    21    assume_role_policy = <<EOF
    22  {
    23    "Version": "2012-10-17",
    24    "Statement": [
    25      {
    26        "Action": "sts:AssumeRole",
    27        "Principal": {
    28          "Service": "lambda.amazonaws.com"
    29        },
    30        "Effect": "Allow",
    31        "Sid": ""
    32      }
    33    ]
    34  }
    35  EOF
    36  }
    37  
    38  resource "aws_lambda_function" "test_lambda" {
    39    filename         = "lambda_function_payload.zip"
    40    function_name    = "lambda_function_name"
    41    role             = "${aws_iam_role.iam_for_lambda.arn}"
    42    handler          = "exports.test"
    43    source_code_hash = "${base64sha256(file("lambda_function_payload.zip"))}"
    44  
    45    environment {
    46      variables = {
    47        foo = "bar"
    48      }
    49    }
    50  }
    51  ```
    52  
    53  ## Argument Reference
    54  
    55  * `filename` - (Optional) A [zip file][2] containing your lambda function source code. If defined, The `s3_*` options cannot be used.
    56  * `s3_bucket` - (Optional) The S3 bucket location containing your lambda function source code. Conflicts with `filename`.
    57  * `s3_key` - (Optional) The S3 key of a [zip file][2] containing your lambda function source code. Conflicts with `filename`.
    58  * `s3_object_version` - (Optional) The object version of your lambda function source code. Conflicts with `filename`.
    59  * `function_name` - (Required) A unique name for your Lambda Function.
    60  * `dead_letter_config` - (Optional) Nested block to configure the function's *dead letter queue*. See details below.
    61  * `handler` - (Required) The function [entrypoint][3] in your code.
    62  * `role` - (Required) IAM role attached to the Lambda Function. This governs both who / what can invoke your Lambda Function, as well as what resources our Lambda Function has access to. See [Lambda Permission Model][4] for more details.
    63  * `description` - (Optional) Description of what your Lambda Function does.
    64  * `memory_size` - (Optional) Amount of memory in MB your Lambda Function can use at runtime. Defaults to `128`. See [Limits][5]
    65  * `runtime` - (Required) See [Runtimes][6] for valid values.
    66  * `timeout` - (Optional) The amount of time your Lambda Function has to run in seconds. Defaults to `3`. See [Limits][5]
    67  * `publish` - (Optional) Whether to publish creation/change as new Lambda Function Version. Defaults to `false`.
    68  * `vpc_config` - (Optional) Provide this to allow your function to access your VPC. Fields documented below. See [Lambda in VPC][7]
    69  * `environment` - (Optional) The Lambda environment's configuration settings. Fields documented below.
    70  * `kms_key_arn` - (Optional) The ARN for the KMS encryption key.
    71  * `source_code_hash` - (Optional) Used to trigger updates. This is only useful in conjunction with `filename`.
    72    The only useful value is `${base64sha256(file("file.zip"))}`.
    73  
    74  **dead\_letter\_config** is a child block with a single argument:
    75  
    76  * `target_arn` - (Required) The ARN of an SNS topic or SQS queue to notify when an invocation fails. If this
    77    option is used, the function's IAM role must be granted suitable access to write to the target object,
    78    which means allowing either the `sns:Publish` or `sqs:SendMessage` action on this ARN, depending on
    79    which service is targeted.
    80  
    81  **vpc\_config** requires the following:
    82  
    83  * `subnet_ids` - (Required) A list of subnet IDs associated with the Lambda function.
    84  * `security_group_ids` - (Required) A list of security group IDs associated with the Lambda function.
    85  
    86  ~> **NOTE:** if both `subnet_ids` and `security_group_ids` are empty then vpc_config is considered to be empty or unset.
    87  
    88  For **environment** the following attributes are supported:
    89  
    90  * `variables` - (Optional) A map that defines environment variables for the Lambda function.
    91  
    92  ## Attributes Reference
    93  
    94  * `arn` - The Amazon Resource Name (ARN) identifying your Lambda Function.
    95  * `qualified_arn` - The Amazon Resource Name (ARN) identifying your Lambda Function Version
    96    (if versioning is enabled via `publish = true`).
    97  * `version` - Latest published version of your Lambda Function.
    98  * `last_modified` - The date this resource was last modified.
    99  * `kms_key_arn` - (Optional) The ARN for the KMS encryption key.
   100  * `source_code_hash` - Base64-encoded representation of raw SHA-256 sum of the zip file
   101    provided either via `filename` or `s3_*` parameters.
   102  
   103  [1]: https://docs.aws.amazon.com/lambda/latest/dg/welcome.html
   104  [2]: https://docs.aws.amazon.com/lambda/latest/dg/walkthrough-s3-events-adminuser-create-test-function-create-function.html
   105  [3]: https://docs.aws.amazon.com/lambda/latest/dg/walkthrough-custom-events-create-test-function.html
   106  [4]: https://docs.aws.amazon.com/lambda/latest/dg/intro-permission-model.html
   107  [5]: https://docs.aws.amazon.com/lambda/latest/dg/limits.html
   108  [6]: https://docs.aws.amazon.com/lambda/latest/dg/API_CreateFunction.html#SSS-CreateFunction-request-Runtime
   109  [7]: http://docs.aws.amazon.com/lambda/latest/dg/vpc.html
   110  
   111  ## Import
   112  
   113  Lambda Functions can be imported using the `function_name`, e.g.
   114  
   115  ```
   116  $ terraform import aws_lambda_function.tesr_lambda my_test_lambda_function
   117  ```