--- layout: "aws" page_title: "AWS: aws_lambda_function" sidebar_current: "docs-aws-resource-lambda-function" description: |- 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. --- # aws\_lambda\_function 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. For information about Lambda and how to use it, see [What is AWS Lambda?][1] ## Example Usage ``` resource "aws_iam_role" "iam_for_lambda" { name = "iam_for_lambda" assume_role_policy = < **NOTE:** if both `subnet_ids` and `security_group_ids` are empty then vpc_config is considered to be empty or unset. For **environment** the following attributes are supported: * `variables` - (Optional) A map that defines environment variables for the Lambda function. ## Attributes Reference * `arn` - The Amazon Resource Name (ARN) identifying your Lambda Function. * `qualified_arn` - The Amazon Resource Name (ARN) identifying your Lambda Function Version (if versioning is enabled via `publish = true`). * `version` - Latest published version of your Lambda Function. * `last_modified` - The date this resource was last modified. * `kms_key_arn` - (Optional) The ARN for the KMS encryption key. * `source_code_hash` - Base64-encoded representation of raw SHA-256 sum of the zip file provided either via `filename` or `s3_*` parameters. [1]: https://docs.aws.amazon.com/lambda/latest/dg/welcome.html [2]: https://docs.aws.amazon.com/lambda/latest/dg/walkthrough-s3-events-adminuser-create-test-function-create-function.html [3]: https://docs.aws.amazon.com/lambda/latest/dg/walkthrough-custom-events-create-test-function.html [4]: https://docs.aws.amazon.com/lambda/latest/dg/intro-permission-model.html [5]: https://docs.aws.amazon.com/lambda/latest/dg/limits.html [6]: https://docs.aws.amazon.com/lambda/latest/dg/API_CreateFunction.html#SSS-CreateFunction-request-Runtime [7]: http://docs.aws.amazon.com/lambda/latest/dg/vpc.html ## Import Lambda Functions can be imported using the `function_name`, e.g. ``` $ terraform import aws_lambda_function.tesr_lambda my_test_lambda_function ```