AWS Fundamentals LogoAWS Fundamentals
Back to Blog

Marrying Terraform and Serverless Framework by Using the Parameter Store

Tobias Schmidt
by Tobias Schmidt
Marrying Terraform and Serverless Framework by Using the Parameter Store

Table of Contents

Jump to a section

If you want to build a serverless application, the Serverless Framework gives you a head start if you want to have your service up and running fast. In very few lines of YAML, you’re able to configure Lambda functions and expose them via REST, HTTP, or event Socket Gateways. You’re able to attach authorizers easily and you can do a lot of fine-tuning like for example adding CloudWatch triggers for regularly invoking your functions to stay warm.

But what if your application ecosystems evolve around more than Lambda functions and gateways? Most likely you’ve used Terraform for provisioning and managing your infrastructure and I don’t need to highlight all of its awesome features. Surely, you could define your remaining infrastructure by extending your serverless.yml file with custom CloudFormation resources. But that’s not fun and you will miss Terraform soon.

There’s an easy way to combine both.

Getting the best of the two worlds

You can maintain all your infrastructure, excluding your Lambda functions and gateways, with Terraform and then just expose everything you need in your serverless functions via the Parameter Store. For example, if you want to use DynamoDB and its streams capability, just expose the ARN of the stream:

resource "aws_ssm_parameter" "stream_arn" {
  type        = "String"
  name        = "transaction-stream-arn"
  value       = aws_dynamodb_table.transaction.stream_arn
  overwrite   = true

  lifecycle {
    ignore_changes = [value]
  }
}

Afterward, you can use the exposed parameters in your serverless.yml via ${ssm.eu-central-1:/transaction-stream-arn}. The only thing you need to make sure is that your dependencies are always from your serverless infrastructure to infrastructure created via Terraform because you need to apply Terraform at first and you can’t have cyclic dependencies.

Combining Serverless Framework with Terraform via Parameter Store

That’s it. 🎉

AWS Lambda Infographic

AWS Lambda on One Page (No Fluff)

Skip the 300-page docs. Our Lambda cheat sheet covers everything from cold starts to concurrency limits - the stuff we actually use daily.

HD quality, print-friendly. Stick it next to your desk.

Privacy Policy
By entering your email, you are opting in for our twice-a-month AWS newsletter. Once in a while, we'll promote our paid products. We'll never send you spam or sell your data.

If you found this article on marrying Terraform and Serverless Framework insightful, you might also enjoy these related posts:

Related Posts

Discover similar content using semantic vector search powered by AWS S3 Vectors. These posts share conceptual similarities based on machine learning embeddings.

vector_search.sh
~/blog/related-posts
$ aws s3-vectors query --embedding-model titan --index bedrock-kb-default --similarity cosine --top-k 3
✓ Found 3 semantic matches:
[MATCH_1]
cosine_similarity:0.776108
vector_dim: 1536 | euclidean_dist: 0.448
Introduction to AWS Lambda: A Starter Guide
cover.webp...
Introduction to AWS Lambda: A Starter Guide
aws_service:lambdatimestamp:2021-05-27
slug: /blog/starter-guide-things-i-wish-i-knew-before-for-aws-lambdaembedding_match: 77.61%
[MATCH_2]
cosine_similarity:0.616219
vector_dim: 1536 | euclidean_dist: 0.768
What Is Terraform? A Beginner's Guide to the Most Famous Infrastructure-as-Code Tool
cover.webp...
What Is Terraform? A Beginner's Guide to the Most Famous Infrastructure-as-Code Tool
aws_service:terraformtimestamp:2023-03-08
slug: /blog/what-is-terraformembedding_match: 61.62%
[MATCH_3]
cosine_similarity:0.588815
vector_dim: 1536 | euclidean_dist: 0.822
Serverless Framework Unlimited: Resource Extensions
cover.webp...
Serverless Framework Unlimited: Resource Extensions
aws_service:lambdatimestamp:2023-05-25
slug: /blog/serverless-framework-resource-extensionsembedding_match: 58.88%
Query executed in ~37ms
Powered by AWS S3 Vectors
$ _

Related Posts

⚡ Powered by AWS S3 Vectors
AWS Lambda Infographic

AWS Lambda on One Page (No Fluff)

Skip the 300-page docs. Our Lambda cheat sheet covers everything from cold starts to concurrency limits - the stuff we actually use daily.

HD quality, print-friendly. Stick it next to your desk.

Privacy Policy
By entering your email, you are opting in for our twice-a-month AWS newsletter. Once in a while, we'll promote our paid products. We'll never send you spam or sell your data.