https://github.com/sbstjn/cdk-lambda-fleet
Deploy AWS Lambda functions using docker images to ECR with AWS CDK
https://github.com/sbstjn/cdk-lambda-fleet
aws aws-cdk cdk construct lambda serverless
Last synced: 10 months ago
JSON representation
Deploy AWS Lambda functions using docker images to ECR with AWS CDK
- Host: GitHub
- URL: https://github.com/sbstjn/cdk-lambda-fleet
- Owner: sbstjn
- License: mit
- Created: 2020-12-06T14:57:47.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2020-12-06T18:46:03.000Z (about 5 years ago)
- Last Synced: 2025-03-15T17:07:33.942Z (11 months ago)
- Topics: aws, aws-cdk, cdk, construct, lambda, serverless
- Language: TypeScript
- Homepage: https://sbstjn.com/blog/aws-cdk-lambda-fleet-multiple-docker-images-container/
- Size: 95.7 KB
- Stars: 20
- Watchers: 3
- Forks: 6
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# AWS CDK: Lambda Fleet
[](https://github.com/sbstjn/cdk-lambda-fleet/blob/master/LICENSE.md)
[](https://www.npmjs.com/package/cdk-lambda-fleet)
> Deploy multiple AWS Lambda functions as container images to Amazon ECR with CDK.
## Examples
- [`src/lambda-node-example`](src/lambda-node-example)
- [`src/lambda-python-example`](src/lambda-python-example)
- [`src/lambda-typescript-example`](src/lambda-typescript-example)
## CDK Construct
When using the AWS CDK in TypeScript, you can use the published `LambdaFleet` construct:
```bash
$ > yarn install cdk-lambda-fleet
```
```typescript
import * as path from "path";
import * as cdk from "@aws-cdk/core";
import { LambdaFleet } from "cdk-lambda-fleet";
export class FleetStack extends cdk.Stack {
constructor(scope: cdk.App, id: string, props?: cdk.StackProps) {
super(scope, id, props);
new LambdaFleet(this, "Fleet", {
path: path.resolve(__dirname, "../src"),
});
}
}
```
### Configuration
You can fork this repository and create a folder like `src/lambda-python-example` and store a `Dockerfile` there:
```Dockerfile
FROM amazon/aws-lambda-python:3.8
COPY requirements.txt ./
RUN pip install -r requirements.txt
COPY handler.py ./
CMD [ "handler.run" ]
```
Using the **AWS CDK**, a docker image will be created and deployed to **Amazon ECR** for every folder in `src/`. After uploading the image, an **AWS Lambda** will be created or updated to use the latest image.
## Deployment
```bash
# Deploy all functions
$ > yarn deploy
[…]
Fleet.FleetLambdaNodeExampleArnXYZ = "arn:aws:lambda:eu-central-1:123:function:Fleet-FleetLambdaNodeExampleXYZ-XYZ"
Fleet.FleetLambdaPythonExampleArnXYZ = "arn:aws:lambda:eu-central-1:123:function:Fleet-FleetLambdaPythonExampleXYZ-XYZ"
Fleet.FleetLambdaTypescriptExampleArnXYZ = "arn:aws:lambda:eu-central-1:123:function:Fleet-FleetLambdaTypescriptExampleXYZ-XYZ"
```