github.com/ves/terraform@v0.8.0-beta2/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 assume_role_policy = <<EOF 21 { 22 "Version": "2012-10-17", 23 "Statement": [ 24 { 25 "Action": "sts:AssumeRole", 26 "Principal": { 27 "Service": "lambda.amazonaws.com" 28 }, 29 "Effect": "Allow", 30 "Sid": "" 31 } 32 ] 33 } 34 EOF 35 } 36 37 resource "aws_lambda_function" "test_lambda" { 38 filename = "lambda_function_payload.zip" 39 function_name = "lambda_function_name" 40 role = "${aws_iam_role.iam_for_lambda.arn}" 41 handler = "exports.test" 42 source_code_hash = "${base64sha256(file("lambda_function_payload.zip"))}" 43 } 44 ``` 45 46 ## Argument Reference 47 48 * `filename` - (Optional) A [zip file][2] containing your lambda function source code. If defined, The `s3_*` options cannot be used. 49 * `s3_bucket` - (Optional) The S3 bucket location containing your lambda function source code. Conflicts with `filename`. 50 * `s3_key` - (Optional) The S3 key containing your lambda function source code. Conflicts with `filename`. 51 * `s3_object_version` - (Optional) The object version of your lambda function source code. Conflicts with `filename`. 52 * `function_name` - (Required) A unique name for your Lambda Function. 53 * `handler` - (Required) The function [entrypoint][3] in your code. 54 * `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. 55 * `description` - (Optional) Description of what your Lambda Function does. 56 * `memory_size` - (Optional) Amount of memory in MB your Lambda Function can use at runtime. Defaults to `128`. See [Limits][5] 57 * `runtime` - (Optional) Defaults to `nodejs`. See [Runtimes][6] for valid values. 58 * `timeout` - (Optional) The amount of time your Lambda Function has to run in seconds. Defaults to `3`. See [Limits][5] 59 * `publish` - (Optional) Whether to publish creation/change as new Lambda Function Version. Defaults to `false`. 60 * `vpc_config` - (Optional) Provide this to allow your function to access your VPC. Fields documented below. See [Lambda in VPC][7] 61 * `source_code_hash` - (Optional) Used to trigger updates. This is only useful in conjunction with `filename`. 62 The only useful value is `${base64sha256(file("file.zip"))}`. 63 64 **vpc\_config** requires the following: 65 66 * `subnet_ids` - (Required) A list of subnet IDs associated with the Lambda function. 67 * `security_group_ids` - (Required) A list of security group IDs associated with the Lambda function. 68 69 ~> **NOTE:** if both `subnet_ids` and `security_group_ids` are empty then vpc_config is considered to be empty or unset. 70 71 ## Attributes Reference 72 73 * `arn` - The Amazon Resource Name (ARN) identifying your Lambda Function. 74 * `qualified_arn` - The Amazon Resource Name (ARN) identifying your Lambda Function Version 75 (if versioning is enabled via `publish = true`). 76 * `version` - Latest published version of your Lambda Function 77 * `last_modified` - The date this resource was last modified. 78 * `source_code_hash` - Base64-encoded representation of raw SHA-256 sum of the zip file 79 provided either via `filename` or `s3_*` parameters 80 81 [1]: https://docs.aws.amazon.com/lambda/latest/dg/welcome.html 82 [2]: https://docs.aws.amazon.com/lambda/latest/dg/walkthrough-s3-events-adminuser-create-test-function-create-function.html 83 [3]: https://docs.aws.amazon.com/lambda/latest/dg/walkthrough-custom-events-create-test-function.html 84 [4]: https://docs.aws.amazon.com/lambda/latest/dg/intro-permission-model.html 85 [5]: https://docs.aws.amazon.com/lambda/latest/dg/limits.html 86 [6]: https://docs.aws.amazon.com/lambda/latest/dg/API_CreateFunction.html#SSS-CreateFunction-request-Runtime 87 [7]: http://docs.aws.amazon.com/lambda/latest/dg/vpc.html 88 89 ## Import 90 91 Lambda Functions can be imported using the `function_name`, e.g. 92 93 ``` 94 $ terraform import aws_lambda_function.tesr_lambda my_test_lambda_function 95 ```