3 ms·
How do you use Terraform with Lambda? That's been one of the huge painpoints in my limited Lambda experience. All the CI tools (SAM, Serverless Framework, e.g
by luhn 6y ago
How do you use Terraform with Lambda? That's been one of the huge painpoints in my limited Lambda experience. All the CI tools (SAM, Serverless Framework, e.g.) seems to want to handle the IaaS part themselves and step on Terraform's toes. I just want to set everything up with Terraform and then have a nice simple tool to build and deploy the application.
- lovehashbrowns 6y agoWe use terraform and terragrunt by themselves to deploy lambdas. No frameworks. It's slightly more work, I guess. But deploying and understanding how deployments happen is easier this way. Plus, getting any kind of framework approved in a corporation is annoying as heck, whereas we already use terraform and terragrunt. https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/lambda_function https://registry.terraform.io/providers/hashicorp/aws/latest... The biggest annoyance is unit testing, although it forces certain good habits on us. So for example, since we don't use SAM, we have to do unit testing separately (our code is in Python). But because we can't exactly run a lambda via Python, we have to put most of our code in the layers that our lambdas import. So we run unit tests on the layers, and the positive is that we can essentially copy and paste the code that our lambdas would run into the unit tests. And then we can keep it DRY because almost all the code is in layers, and that incentivizes us to create generic functions that can be used across all of our lambdas. For things like unit testing DynamoDB, we use Moto which works exceptionally well. https://pypi.org/project/moto/ https://pypi.org/project/moto/ More detail: Our terraform has infrastructure code for: API Gateways Hard-coded API keys we use for testing DynamoDB tables IAM roles used by the Lambdas and Step Functions Lambdas themselves s3 buckets used for the Lambda zip files and state Step functions
- rjbwork 6y agoWe have build our apps and create a lambda zip file and deploy it out of band of our Terraform. We just upload the zip file to S3 after deploy and if Terraform runs and makes a change to the Lambda, it deploys the most recently deployed version automatically. We did this so we could totally separate our applications and the infrastructure as code stuff since infrastructure changes at a drastically slower rate than applications.