feat: Add Lambda Managed Instances pattern (Python, SAM/CloudFormation) - #3253
awsTest1992 wants to merge 5 commits into
Conversation
- Narrow IAM wildcard: orchestrator* -> orchestrator:* - Fix casing: 'Durable Lambda Function' -> 'Lambda durable function' - Use single quotes for function-name in test commands - Fix docstring casing: 'Durable Functions' -> 'durable functions' - Add CloudWatch Logs group with 14-day retention
ellisms
left a comment
There was a problem hiding this comment.
Hi @awsTest1992 I started reviewing this and have 2 initial findings that need to be reviewed before I test:
- It looks like the route tables are missing from the VPC/subnet definitions. Can you confirm this will still be a valid deploy? See the networking documentation: https://docs.aws.amazon.com/lambda/latest/dg/lambda-managed-instances-networking.html
- A second directory, lambda-durable-saga-python-sam, is included in this PR. Was that intended?
| @@ -0,0 +1,115 @@ | |||
| # Lambda Managed Instances with SAM (Python) | |||
|
|
|||
| This pattern deploys a Python Lambda function running on AWS Lambda Managed Instances using CloudFormation. Lambda Managed Instances enables you to run functions on EC2 instances while AWS handles lifecycle management, patching, routing, and scaling. You benefit from EC2 pricing (Savings Plans, Reserved Instances) and multi-concurrency support. | |||
There was a problem hiding this comment.
| This pattern deploys a Python Lambda function running on AWS Lambda Managed Instances using CloudFormation. Lambda Managed Instances enables you to run functions on EC2 instances while AWS handles lifecycle management, patching, routing, and scaling. You benefit from EC2 pricing (Savings Plans, Reserved Instances) and multi-concurrency support. | |
| This pattern deploys a Python Lambda function running on AWS Lambda Managed Instances using AWS SAM. Lambda Managed Instances enables you to run functions on EC2 instances while AWS handles lifecycle management, patching, routing, and scaling. You benefit from EC2 pricing (Savings Plans, Reserved Instances) and multi-concurrency support. |
|
|
||
| 2. **Capacity Provider Operator IAM Role**: An IAM role with the `AWSLambdaManagedEC2ResourceOperator` managed policy that Lambda uses to provision and manage EC2 instances. | ||
|
|
||
| 3. **Lambda Capacity Provider**: Defines where functions run — VPC config, instance architecture (ARM64/Graviton4), and the operator role for instance management. |
There was a problem hiding this comment.
| 3. **Lambda Capacity Provider**: Defines where functions run — VPC config, instance architecture (ARM64/Graviton4), and the operator role for instance management. | |
| 3. **Lambda Capacity Provider**: Defines where functions run — VPC config, instance architecture (arm64 / AWS Graviton), and the operator role for instance management. |
Address @ellisms review on PR aws-samples#3253: - Add private route table + subnet associations so the private subnets have an explicit table (was missing, using only the VPC main table) - Add PrivateLink egress with no internet route: interface endpoints for CloudWatch Logs, ECR (api + dkr), and EC2, plus an S3 gateway endpoint, so Managed Instances can send logs and pull the runtime image privately - Remove the accidental lambda-durable-saga-python-sam directory - Remove src/ and keep the inline ZipFile as the single source of truth - README: 'using CloudFormation' -> 'using AWS SAM'; 'ARM64/Graviton4' -> 'arm64 / AWS Graviton'; document the private networking Verified: sam validate --lint and cfn-lint pass clean; deployed to a test account, confirmed private route table + endpoints, successful invoke on managed instances, and log delivery via the private logs endpoint; stack deleted after testing.
|
Thanks for the review @ellisms! I've pushed a commit addressing all the feedback. 1. Missing route tables / networking
The route table has only the 2. Stray 3. Inline code vs 4 & 5. README wording
Verification
Ready for another look when you have a chance. Thanks! |
ellisms
left a comment
There was a problem hiding this comment.
Thanks for the updates @awsTest1992 . Requesting a few additional minor changes.
| 1. From the command line, use AWS SAM to build and deploy: | ||
| ``` | ||
| sam build | ||
| sam deploy --guided |
There was a problem hiding this comment.
During testing I had to add --capabilities CAPABILITY_NAMED_IAM to sam deploy.
| } | ||
| ``` | ||
|
|
||
| 3. Test multi-concurrency by invoking in parallel: |
There was a problem hiding this comment.
Provide a sample expected response
| @@ -0,0 +1,115 @@ | |||
| # Lambda Managed Instances with SAM (Python) | |||
There was a problem hiding this comment.
| # Lambda Managed Instances with SAM (Python) | |
| # AWS Lambda Managed Instances with AWS SAM (Python) |
| @@ -0,0 +1,115 @@ | |||
| # Lambda Managed Instances with SAM (Python) | |||
|
|
|||
| This pattern deploys a Python Lambda function running on AWS Lambda Managed Instances using AWS SAM. Lambda Managed Instances enables you to run functions on EC2 instances while AWS handles lifecycle management, patching, routing, and scaling. You benefit from EC2 pricing (Savings Plans, Reserved Instances) and multi-concurrency support. | |||
There was a problem hiding this comment.
| This pattern deploys a Python Lambda function running on AWS Lambda Managed Instances using AWS SAM. Lambda Managed Instances enables you to run functions on EC2 instances while AWS handles lifecycle management, patching, routing, and scaling. You benefit from EC2 pricing (Savings Plans, Reserved Instances) and multi-concurrency support. | |
| This pattern deploys a Python Lambda function running on AWS Lambda Managed Instances using AWS SAM. Lambda Managed Instances enables you to run functions on Amazon EC2 instances while AWS handles lifecycle management, patching, routing, and scaling. You benefit from EC2 pricing (Savings Plans, Reserved Instances) and multi-concurrency support. |
|
|
||
| This pattern creates: | ||
|
|
||
| 1. **VPC with private subnets**: Two private subnets across availability zones for the capacity provider. The subnets use a dedicated private route table with no internet route (no NAT, no internet gateway). Egress to AWS services stays inside the VPC via PrivateLink: interface endpoints for CloudWatch Logs, Amazon ECR (`ecr.api` and `ecr.dkr`), and Amazon EC2, plus an S3 gateway endpoint for pulling the runtime image layers. |
There was a problem hiding this comment.
| 1. **VPC with private subnets**: Two private subnets across availability zones for the capacity provider. The subnets use a dedicated private route table with no internet route (no NAT, no internet gateway). Egress to AWS services stays inside the VPC via PrivateLink: interface endpoints for CloudWatch Logs, Amazon ECR (`ecr.api` and `ecr.dkr`), and Amazon EC2, plus an S3 gateway endpoint for pulling the runtime image layers. | |
| 1. **VPC with private subnets**: Two private subnets across availability zones for the capacity provider. The subnets use a dedicated private route table with no internet route (no NAT, no internet gateway). Egress to AWS services stays inside the VPC via PrivateLink: interface endpoints for Amazon CloudWatch Logs, Amazon ECR (`ecr.api` and `ecr.dkr`), and Amazon EC2, plus an Amazon S3 gateway endpoint for pulling the runtime image layers. |
|
|
||
| 1. **VPC with private subnets**: Two private subnets across availability zones for the capacity provider. The subnets use a dedicated private route table with no internet route (no NAT, no internet gateway). Egress to AWS services stays inside the VPC via PrivateLink: interface endpoints for CloudWatch Logs, Amazon ECR (`ecr.api` and `ecr.dkr`), and Amazon EC2, plus an S3 gateway endpoint for pulling the runtime image layers. | ||
|
|
||
| 2. **Capacity Provider Operator IAM Role**: An IAM role with the `AWSLambdaManagedEC2ResourceOperator` managed policy that Lambda uses to provision and manage EC2 instances. |
There was a problem hiding this comment.
| 2. **Capacity Provider Operator IAM Role**: An IAM role with the `AWSLambdaManagedEC2ResourceOperator` managed policy that Lambda uses to provision and manage EC2 instances. | |
| 2. **Capacity Provider Operator IAM Role**: An Amazon IAM role with the `AWSLambdaManagedEC2ResourceOperator` managed policy that Lambda uses to provision and manage EC2 instances. |
Apply maintainer-requested wording and instruction fixes for the lambda-managed-instances-python-sam pattern: - Retitle to 'AWS Lambda Managed Instances with AWS SAM (Python)' - Use full service names (Amazon EC2, Amazon CloudWatch Logs, Amazon S3, Amazon IAM) in the intro and How it works section - Add --capabilities CAPABILITY_NAMED_IAM to sam deploy (the template creates a named IAM role for the capacity provider operator) - Replace the placeholder timestamp with a concrete sample response
Issue #, if available:
Description of changes:
Adds a SAM/CloudFormation-based pattern for AWS Lambda Managed Instances with Python. This fills the gap where CDK and Terraform versions exist but no SAM equivalent was available.
Pattern includes:
Tested: Deployed and invoked successfully in us-east-1.
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.