[{"data":1,"prerenderedAt":211},["ShallowReactive",2],{"content-guides-building-serverless-applications-with-terraform-01-introduction":3},{"markdown":4,"frontMatterAttributes":5,"bodyRaw":22,"contributorPaths":23,"menuType":28,"contentName":29,"slug":30,"readingTime":31,"menu":32,"nextDocItem":44,"previousDocItem":210},"\u003Cp>Infrastructure-as-code (IaC) is a methodology of applying techniques commonly used for source code to infrastructure templates. IaC allows engineering teams to define required infrastructure in either a declarative or imperative way, and enables capabilities such as version control, audit, and CI\u002FCD. \u003C\u002Fp>\n\u003Cp>\u003Ca href=\"https:\u002F\u002Fterraform.io\">Hashicorp Terraform\u003C\u002Fa> is an IaC tool that allows engineering teams to define and deploy their applications using a declarative, human-readable syntax. This guide is targeting engineering teams that are looking for guidance and samples for using Terraform to build serverless applications. \u003C\u002Fp>\n\u003Cp>While this guide covers some of the Terraform basics, it assumes you do have previous experience and some level of proficiency with Terraform. \u003C\u002Fp>\n\u003Ch2>Overview\u003C\u002Fh2>\n\u003Cp>One of the major benefits of using IaC is the fact that it allows to easily create multiple environments from the same infrastructure template. This helps engineering teams to ensure that different application environments can be easily replicated and kept in sync, reducing the risk of application functionality breaking. This is applicable to multiple scenarios. One common scenario is using IaC to deploy development, testing, and production environments. Another example is using IaC to deploy a set of dedicated data plane assets in a SaaS application, where each tenant has their own set of single-tenant infrastructure resources. IaC reduces the risk of human error and allows to automate replicating changes across environments. \u003C\u002Fp>\n\u003Cp>Over the years IaC practices and tools evolved to cover thousands of various resource types, many of them going beyond the original definition of &quot;infrastructure&quot;. For example, today you can use IaC to manage resources such as user accounts or even application settings. Serverless applications are no different. Building Serverless applications with IaC tools is a common task, and we highly recommend you use IaC tools for building your Serverless applications on AWS. \u003C\u002Fp>\n\u003Ch2>Infrastructure-as-code tools\u003C\u002Fh2>\n\u003Cp>There are various IaC tools engineering teams use for building Serverless applications. AWS provides IaC tools such as \u003Ca href=\"https:\u002F\u002Faws.amazon.com\u002Fserverless\u002Fsam\u002F\">AWS Serverless Application Model\u003C\u002Fa> (SAM), and \u003Ca href=\"https:\u002F\u002Faws.amazon.com\u002Fcdk\u002F\">AWS Cloud Development Kit\u003C\u002Fa> (CDK). Other IaC tools, such as \u003Ca href=\"https:\u002F\u002Fterraform.io\">Hashicorp Terraform\u003C\u002Fa>, are provided by AWS Partners or 3rd party vendors. Selecting which tool to use depends on several factors, such as whether you want to use declarative or imperative approach, or whether your organization is already using a particular IaC methodology and you&#39;d like to reuse the knowledge. \u003C\u002Fp>\n\u003Cp>\u003Ca href=\"https:\u002F\u002Faws.amazon.com\u002Fserverless\u002Fsam\u002F\">AWS SAM\u003C\u002Fa> is an open-source framework for building serverless applications. SAM is a superset of \u003Ca href=\"https:\u002F\u002Faws.amazon.com\u002Fcloudformation\u002F\">AWS CloudFormation\u003C\u002Fa>, and provides a shorthand syntax to express multiple types of serverless resources, such as functions, APIs, databases, and event source mappings. With SAM, you model your environments using YAML, which is automatically converted to CloudFormation syntax and deployed to AWS using the SAM CLI. SAM also provides local tools, allowing engineers to test their functions locally or simulate an API Gateway. \u003C\u002Fp>\n\u003Cp>\u003Ca href=\"https:\u002F\u002Faws.amazon.com\u002Fcdk\">AWS CDK\u003C\u002Fa> takes a programmatic approach. With CDK you model your environments using one of the supported programming languages, such as TypeScript, Python, or Java. Similar to SAM, the CDK CLI will automatically convert your environment definition to CloudFormation syntax and deploy it to AWS. CDK can be used \u003Ca href=\"https:\u002F\u002Fdocs.aws.amazon.com\u002Fserverless-application-model\u002Flatest\u002Fdeveloperguide\u002Fserverless-cdk-getting-started.html\">together with SAM\u003C\u002Fa>, allowing engineers to use SAM for local testing when their environments are defined with CDK. \u003C\u002Fp>\n\u003Cp>\u003Ca href=\"https:\u002F\u002Fterraform.io\">Hashicorp Terraform\u003C\u002Fa> is a popular IaC tool coming from an AWS Partner, widely adopted in the industry. With Terraform you use the \u003Ca href=\"https:\u002F\u002Fdeveloper.hashicorp.com\u002Fterraform\u002Flanguage\">HashiCorp Terraform Language\u003C\u002Fa> (HCL) to write Terraform configuration files (.tf). You use those files to model your environments. Similar to CDK, Terraform can also integrate with SAM when building Serverless applications for ease of local testing, as you will see in this guide. \u003C\u002Fp>\n\u003Cp>Throughout this guide you will learn how to use Terraform for building serverless applications. You will follow a process of gradually building and evolving serverless application architecture. You will learn how to address IAM and observability, and how to use SAM together with Terraform for testing your applications locally. Towards the end of this guide you will learn how to scale-up your Terraform templates for serverless applications by adding support for multiple environments and modularizing infrastructure and application code.\u003C\u002Fp>\n",{"title":6,"order":7,"authors":8,"resources":11},"1. Introduction",1,[9,10],"Anton Aleksandrov","Debasis Rath",[12,16,19],{"link":13,"text":14,"type":15},"https:\u002F\u002Faws.amazon.com\u002Fserverless\u002Fsam\u002F","AWS Serverless Application Model (SAM)","link",{"link":17,"text":18,"type":15},"https:\u002F\u002Faws.amazon.com\u002Fcdk\u002F","AWS Cloud Development Kit (CDK)",{"link":20,"text":21,"type":15},"https:\u002F\u002Fwww.terraform.io\u002F","Hashicorp Terraform","Infrastructure-as-code (IaC) is a methodology of applying techniques commonly used for source code to infrastructure templates. IaC allows engineering teams to define required infrastructure in either a declarative or imperative way, and enables capabilities such as version control, audit, and CI\u002FCD. \n\n[Hashicorp Terraform](https:\u002F\u002Fterraform.io) is an IaC tool that allows engineering teams to define and deploy their applications using a declarative, human-readable syntax. This guide is targeting engineering teams that are looking for guidance and samples for using Terraform to build serverless applications. \n\nWhile this guide covers some of the Terraform basics, it assumes you do have previous experience and some level of proficiency with Terraform. \n\n## Overview\n\nOne of the major benefits of using IaC is the fact that it allows to easily create multiple environments from the same infrastructure template. This helps engineering teams to ensure that different application environments can be easily replicated and kept in sync, reducing the risk of application functionality breaking. This is applicable to multiple scenarios. One common scenario is using IaC to deploy development, testing, and production environments. Another example is using IaC to deploy a set of dedicated data plane assets in a SaaS application, where each tenant has their own set of single-tenant infrastructure resources. IaC reduces the risk of human error and allows to automate replicating changes across environments. \n\nOver the years IaC practices and tools evolved to cover thousands of various resource types, many of them going beyond the original definition of \"infrastructure\". For example, today you can use IaC to manage resources such as user accounts or even application settings. Serverless applications are no different. Building Serverless applications with IaC tools is a common task, and we highly recommend you use IaC tools for building your Serverless applications on AWS. \n\n## Infrastructure-as-code tools\n\nThere are various IaC tools engineering teams use for building Serverless applications. AWS provides IaC tools such as [AWS Serverless Application Model](https:\u002F\u002Faws.amazon.com\u002Fserverless\u002Fsam\u002F) (SAM), and [AWS Cloud Development Kit](https:\u002F\u002Faws.amazon.com\u002Fcdk\u002F) (CDK). Other IaC tools, such as [Hashicorp Terraform](https:\u002F\u002Fterraform.io), are provided by AWS Partners or 3rd party vendors. Selecting which tool to use depends on several factors, such as whether you want to use declarative or imperative approach, or whether your organization is already using a particular IaC methodology and you'd like to reuse the knowledge. \n\n[AWS SAM](https:\u002F\u002Faws.amazon.com\u002Fserverless\u002Fsam\u002F) is an open-source framework for building serverless applications. SAM is a superset of [AWS CloudFormation](https:\u002F\u002Faws.amazon.com\u002Fcloudformation\u002F), and provides a shorthand syntax to express multiple types of serverless resources, such as functions, APIs, databases, and event source mappings. With SAM, you model your environments using YAML, which is automatically converted to CloudFormation syntax and deployed to AWS using the SAM CLI. SAM also provides local tools, allowing engineers to test their functions locally or simulate an API Gateway. \n  \n[AWS CDK](https:\u002F\u002Faws.amazon.com\u002Fcdk) takes a programmatic approach. With CDK you model your environments using one of the supported programming languages, such as TypeScript, Python, or Java. Similar to SAM, the CDK CLI will automatically convert your environment definition to CloudFormation syntax and deploy it to AWS. CDK can be used [together with SAM](https:\u002F\u002Fdocs.aws.amazon.com\u002Fserverless-application-model\u002Flatest\u002Fdeveloperguide\u002Fserverless-cdk-getting-started.html), allowing engineers to use SAM for local testing when their environments are defined with CDK. \n\n[Hashicorp Terraform](https:\u002F\u002Fterraform.io) is a popular IaC tool coming from an AWS Partner, widely adopted in the industry. With Terraform you use the [HashiCorp Terraform Language](https:\u002F\u002Fdeveloper.hashicorp.com\u002Fterraform\u002Flanguage) (HCL) to write Terraform configuration files (.tf). You use those files to model your environments. Similar to CDK, Terraform can also integrate with SAM when building Serverless applications for ease of local testing, as you will see in this guide. \n\nThroughout this guide you will learn how to use Terraform for building serverless applications. You will follow a process of gradually building and evolving serverless application architecture. You will learn how to address IAM and observability, and how to use SAM together with Terraform for testing your applications locally. Towards the end of this guide you will learn how to scale-up your Terraform templates for serverless applications by adding support for multiple environments and modularizing infrastructure and application code.\n\n\n\n\n\n",[24,25,26,27],"content\u002Fcontributors\u002Fanton-aleksandrov.json","content\u002Fcontributors\u002Fdebasis-rath.json","content\u002Fcontributors\u002Fmatt-ridehalgh.json","content\u002Fcontributors\u002Fluis-cerezo.json","LIST","Building Serverless Applications with Terraform","\u002Fcontent\u002Fguides\u002Fbuilding-serverless-applications-with-terraform\u002F01-introduction","4 min",[33],{"title":34,"content":35},"Guide",[36,44,60,76,95,108,123,145,161,176,194],{"title":6,"order":7,"authors":37,"resources":38,"time":31,"path":42,"id":43,"link":30},[9,10],[39,40,41],{"link":13,"text":14,"type":15},{"link":17,"text":18,"type":15},{"link":20,"text":21,"type":15},"01-introduction","01-introduction.md",{"title":45,"order":46,"authors":47,"resources":48,"time":56,"path":57,"id":58,"link":59},"2. Solution Overview",2,[9,10],[49,50,53],{"link":20,"text":21,"type":15},{"link":51,"text":52,"type":15},"https:\u002F\u002Fdocs.aws.amazon.com\u002Fcli\u002Flatest\u002Fuserguide\u002Fgetting-started-install.htm","AWS CLI",{"link":54,"text":55,"type":15},"https:\u002F\u002Fdocs.aws.amazon.com\u002Fiam\u002F","AWS IAM","3 min","02-solution-overview","02-solution-overview.md","\u002Fcontent\u002Fguides\u002Fbuilding-serverless-applications-with-terraform\u002F02-solution-overview",{"title":61,"order":62,"authors":63,"resources":65,"time":31,"path":73,"id":74,"link":75},"3. S3 buckets",3,[9,10,64],"Matt Ridehalgh",[66,70],{"link":67,"text":68,"type":69},"https:\u002F\u002Fregistry.terraform.io\u002Fproviders\u002Fhashicorp\u002Faws\u002Flatest\u002Fdocs","AWS Terraform Provider","Documentation",{"link":71,"text":72,"type":69},"https:\u002F\u002Fregistry.terraform.io\u002Fproviders\u002Fhashicorp\u002Faws\u002Flatest\u002Fdocs\u002Fresources\u002Fs3_bucket","aws_s3_bucket","03-s3-buckets","03-s3-buckets.md","\u002Fcontent\u002Fguides\u002Fbuilding-serverless-applications-with-terraform\u002F03-s3-buckets",{"title":77,"order":78,"authors":79,"resources":80,"time":31,"path":92,"id":93,"link":94},"4. Lambda functions",4,[9,10],[81,82,85,88],{"link":67,"text":68,"type":69},{"link":83,"text":84,"type":69},"https:\u002F\u002Fregistry.terraform.io\u002Fproviders\u002Fhashicorp\u002Faws\u002Flatest\u002Fdocs\u002Fresources\u002Flambda_function","aws_lambda_function",{"link":86,"text":87,"type":69},"https:\u002F\u002Fdocs.aws.amazon.com\u002Fserverless-application-model\u002Flatest\u002Fdeveloperguide\u002Fterraform-support.html","AWS SAM Terraform support",{"link":89,"text":90,"type":91},"https:\u002F\u002Fgithub.com\u002Faws-samples\u002Fbuilding-serverless-applications-with-terraform\u002Fblob\u002Fmain\u002Flambdas\u002Fgreetings_lambda\u002Findex.mjs","index.mjs","Sample","04-lambda-functions","04-lambda-functions.md","\u002Fcontent\u002Fguides\u002Fbuilding-serverless-applications-with-terraform\u002F04-lambda-functions",{"title":96,"order":97,"authors":98,"resources":99,"time":31,"path":105,"id":106,"link":107},"5. API Gateway",5,[9,10],[100,101,104],{"link":67,"text":68,"type":69},{"link":102,"text":103,"type":69},"https:\u002F\u002Fregistry.terraform.io\u002Fproviders\u002Fhashicorp\u002Faws\u002Flatest\u002Fdocs\u002Fresources\u002Fapi_gateway_rest_api","aws_api_gateway_rest_api",{"link":86,"text":87,"type":69},"05-api-gateway","05-api-gateway.md","\u002Fcontent\u002Fguides\u002Fbuilding-serverless-applications-with-terraform\u002F05-api-gateway",{"title":109,"order":110,"authors":111,"resources":112,"time":31,"path":120,"id":121,"link":122},"6. Asynchronous processing",6,[9,10],[113,114,117],{"link":67,"text":68,"type":69},{"link":115,"text":116,"type":69},"https:\u002F\u002Fregistry.terraform.io\u002Fproviders\u002Fhashicorp\u002Faws\u002Flatest\u002Fdocs\u002Fresources\u002Fsqs_queue","aws_sqs_queue",{"link":118,"text":119,"type":69},"https:\u002F\u002Fregistry.terraform.io\u002Fproviders\u002Fhashicorp\u002Faws\u002Flatest\u002Fdocs\u002Fresources\u002Flambda_event_source_mapping","aws_lambda_event_source_mapping","06-async-processing","06-async-processing.md","\u002Fcontent\u002Fguides\u002Fbuilding-serverless-applications-with-terraform\u002F06-async-processing",{"title":124,"order":125,"authors":126,"resources":127,"time":141,"path":142,"id":143,"link":144},"7. Observability",7,[9,10],[128,129,132,135,138],{"link":67,"text":68,"type":69},{"link":130,"text":131,"type":69},"https:\u002F\u002Fdocs.aws.amazon.com\u002Flambda\u002Flatest\u002Fdg\u002Flambda-monitoring.html","Lambda function observability, monitoring, and troubleshooting",{"linke":133,"text":134,"type":69},"https:\u002F\u002Fdocs.aws.amazon.com\u002Fapigateway\u002Flatest\u002Fdeveloperguide\u002Frest-api-monitor.html","Monitoring API Gateway REST API",{"link":136,"text":137,"type":69},"https:\u002F\u002Fregistry.terraform.io\u002Fproviders\u002Fhashicorp\u002Faws\u002Flatest\u002Fdocs\u002Fresources\u002Fapi_gateway_account","aws_api_gateway_account",{"link":139,"text":140,"type":69},"https:\u002F\u002Fregistry.terraform.io\u002Fproviders\u002Fhashicorp\u002Faws\u002Flatest\u002Fdocs\u002Fresources\u002Fapi_gateway_stage","aws_api_gateway_stage","5 min","07-observability","07-observability.md","\u002Fcontent\u002Fguides\u002Fbuilding-serverless-applications-with-terraform\u002F07-observability",{"title":146,"order":147,"authors":148,"resources":149,"time":157,"path":158,"id":159,"link":160},"8. Modularizing your IaC projects",8,[9,10],[150,151,154],{"link":67,"text":68,"type":69},{"link":152,"text":153,"type":69},"https:\u002F\u002Fdeveloper.hashicorp.com\u002Fterraform\u002Flanguage\u002Fmodules","Terraform Modules",{"link":155,"text":156,"type":91},"https:\u002F\u002Fgithub.com\u002Faws-samples\u002Fbuilding-serverless-applications-with-terraform","Sample project source code","8 min","08-modularizing-your-iac-projects","08-modularizing-your-iac-projects.md","\u002Fcontent\u002Fguides\u002Fbuilding-serverless-applications-with-terraform\u002F08-modularizing-your-iac-projects",{"title":162,"order":163,"authors":164,"resources":165,"time":172,"path":173,"id":174,"link":175},"9. Summary and next steps",9,[9,10],[166,167,169,171],{"link":67,"text":68,"type":69},{"link":168,"text":21,"type":69},"https:\u002F\u002Fdeveloper.hashicorp.com\u002Fterraform",{"link":13,"text":170,"type":69},"AWS SAM",{"link":155,"text":156,"type":91},"2 min","09-summary","09-summary.md","\u002Fcontent\u002Fguides\u002Fbuilding-serverless-applications-with-terraform\u002F09-summary",{"title":177,"order":178,"authors":179,"resources":181,"time":141,"path":191,"id":192,"link":193},"10. Appendix A - Amazon EventBridge",10,[9,10,180],"Luis Cerezo",[182,185,188],{"link":183,"text":184,"type":69},"https:\u002F\u002Fregistry.terraform.io\u002Fproviders\u002Fhashicorp\u002Faws\u002Flatest\u002Fdocs\u002Fresources\u002Fcloudwatch_event_bus","aws_cloudwatch_event_bus Terraform resource",{"link":186,"text":187,"type":69},"https:\u002F\u002Fdocs.aws.amazon.com\u002Fhealth\u002Flatest\u002Fug\u002Fcloudwatch-events-health.html","Monitoring AWS Health events with Amazon EventBridge",{"link":189,"text":190,"type":69},"https:\u002F\u002Fdocs.aws.amazon.com\u002Fhealth\u002Flatest\u002Fug\u002Faws-health-planned-lifecycle-events.html#planned-lifecycle-event-notifications","Planned lifecycle events for AWS Health - What should I expect when I receive a planned lifecycle event notification?","10-appendix-A-EventBridge","10-appendix-A-EventBridge.md","\u002Fcontent\u002Fguides\u002Fbuilding-serverless-applications-with-terraform\u002F10-appendix-A-EventBridge",{"title":195,"order":196,"authors":197,"resources":198,"time":31,"path":207,"id":208,"link":209},"10. Appendix B - AWS Step Functions",11,[9,10,180],[199,202,204],{"link":200,"text":201,"type":69},"https:\u002F\u002Faws.amazon.com\u002Fblogs\u002Fdevops\u002Fbest-practices-for-writing-step-functions-terraform-projects\u002F","Best Practices for Writing Step Functions Terraform Projects",{"link":183,"text":203,"type":69},"cloudwatch_event_bus terraform resource",{"link":205,"text":206,"type":69},"https:\u002F\u002Fdocs.aws.amazon.com\u002Fstep-functions\u002Flatest\u002Fdg\u002Fconcepts-amazon-states-language.html","Amazon States Language","10-appendix-B-SFN","10-appendix-B-SFN.md","\u002Fcontent\u002Fguides\u002Fbuilding-serverless-applications-with-terraform\u002F10-appendix-B-SFN",null,1790764501819]