[{"data":1,"prerenderedAt":62},["ShallowReactive",2],{"pattern-lambda-layer-terraform":3},{"id":4,"title":5,"architectureURL":6,"cleanup":7,"contributors":10,"deploy":12,"description":16,"extension":17,"framework":18,"gitHub":19,"highlight":6,"introBox":25,"language":38,"level":39,"meta":40,"patternArch":41,"resources":46,"s3URL":6,"services":6,"stem":57,"testing":58,"videoId":6,"__hash__":61},"patterns\u002Fpatterns\u002Flambda-layer-terraform.json","An AWS Lambda function using a Lambda layer",null,{"text":8},[9],"terraform destroy --auto-approve",[11],"content\u002Fcontributors\u002Fglenn-chia-jin-wee.json",{"text":13},[14,15],"terraform init","terraform apply --auto-approve","Create Lambda function with a Lambda layer","json","Terraform",{"template":20},{"repoURL":21,"templateURL":22,"projectFolder":23,"templateFile":24},"https:\u002F\u002Fgithub.com\u002Faws-samples\u002Fserverless-patterns\u002Ftree\u002Fmain\u002Flambda-layer-terraform","serverless-patterns\u002Flambda-layer-terraform","lambda-layer-terraform","main.tf",{"headline":26,"text":27},"How it works",[28,29,30,31,32,33,34,35,36,37],"This sample project demonstrates how to deploy a Lambda Function that has a layer added to it.","This includes a sample directory structure that comprises the `dependencies` directory for the python packages and the `src` directory for the Lambda function business logic.","The Terraform code deploys two Lambda functions. Both Lambda functions attempt to import the `mysql-connector-python` package.","However, only one of the Lambda functions has the `mysql-connector-python` layer which allows it to import the package successfully.","This pattern tests both Lambda functions to illustrate the difference when there is a layer added to a Lambda function.","In addition, the Lambda function with the layer lists all files in the `\u002Fopt` directory which allows us to view the files that were uploaded by the layer.","One use case for Lambda layers is to have packages like `mysql-connector-python` shared across various Lambda functions that require connections to RDS MySQL.","Another use case could be to add certificates as layers that can then be used by Lambda Functions to encrypt a connection to a DB instance via SSL\u002FTLS.","The path to these certificates in the `\u002Fopt` directory can be specified in the various `connect` commands.","Using layers reduces the size of uploaded deployment archives and makes it faster to deploy your code.","Python","200",{},{"icon1":42},{"x":43,"y":43,"service":44,"label":45},50,"lambda","AWS Lambda",{"bullets":47},[48,51,54],{"text":49,"link":50},"AWS Lambda Developer Guide - Creating and sharing Lambda layers","https:\u002F\u002Fdocs.aws.amazon.com\u002Flambda\u002Flatest\u002Fdg\u002Fconfiguration-layers.html",{"text":52,"link":53},"AWS Database Blog - IAM role-based authentication to Amazon Aurora from serverless applications. This blog uses the mysql-connector-python package","https:\u002F\u002Faws.amazon.com\u002Fblogs\u002Fdatabase\u002Fiam-role-based-authentication-to-amazon-aurora-from-serverless-applications\u002F",{"text":55,"link":56},"AWS Amazon Relational Database Service (RDS) User Guide - Using SSL\u002FTLS to encrypt a connection to a DB instance","https:\u002F\u002Fdocs.aws.amazon.com\u002FAmazonRDS\u002Flatest\u002FUserGuide\u002FUsingWithRDS.SSL.html","patterns\u002Flambda-layer-terraform",{"text":59},[60],"See the GitHub repo for detailed testing instructions.","kMDpYuq0Xf4pzXqsj3heye7fJX8f7tekokOaeGwr0x8",1778927709639]