aws-samples / aws-samples/aws-sam-terraform-examples
Ability to generate a "Lambda Application"?
- Dominant language
- HCL
- Stars
- 57
- Forks
- 14
- PR merge metrics
- No merged PRs in 30d
Description
Hello,
We're currently using Terraform and AWS SAM together and the lines are just blurry enough in terms of where certain things should live (like Cloudwatch alarms) that this sparked our interest as a way to continue to define all of our infrastructure in TF but continue to leverage AWS SAM for local development.
For extra context, the reason we're using TF and SAM together is that TF sets up the base infra (DB, Redis, etc...) and handles the Route53, SSM, Cloudfront, etc... infra for review apps / staging / production. Our devs started with SAM and we worked TF into the mix after.
Through my research and testing, there does not appear to be a way to create a Lambda application (set of functions grouped together) with Terraform and if I understand AWS SAM correctly, the application is what is run when we invoke `sam local start-api`.
Here is an excerpt of the SAM template generated by the example code in this repo:
```
AwsLambdaFunctionPublishBookReviewBFC97F47:
Type: AWS::Lambda::Function
Properties:
FunctionName: publish-book-review
Architectures:
- x86_64
Environment:
Variables:
DYNAMODB_TABLE_NAME: BookReviews
Code: AwsLambdaFunctionPublishBookReviewBFC97F47
Handler: index.lambda_handler
PackageType: Zip
Runtime: python3.8
Layers: []
Timeout: 30
Metadata:
BuildMethod: makefile
ContextPath: ...
ProjectRootDirectory: ...
SamResourceId: aws_lambda_function.publish_book_review
SkipBuild: false
WorkingDirectory: ...
```
And here's an excerpt for a sample function we have in one of our SAM apps:
```
SampleFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: "src/api/sample"
Handler: sample.lambda_handler
Runtime: python3.9
Tracing: Active
Environment:
Variables:
REDIS_HOST: "redis-host"
REDIS_KEY_PREFIX: "redis-key-prefix"
DB_HOST: "database-host"
DB_USERNAME: "database-username"
DB_PASSWORD: "database-password"
DB_NAME: "database-name"
DB_PORT: "3306"
Architectures:
- x86_64
Events:
Sample:
Type: Api
Properties:
Path: "/sample/{proxy+}"
Method: "post"
Layers:
- !Ref SomeSharedLibs
```
Is there a way to achieve the same SAM template configuration? (Notice the missing `Events` section in the example-generated yaml.
Thanks!
Contributor guide
Assessment
This issue has not been assessed yet.