https://github.com/simonsfoundation/serverless-awslambda-container
Sample repository with code to deploy a custom Ubuntu container to AWS Lambda using the Serverless Framework.
https://github.com/simonsfoundation/serverless-awslambda-container
Last synced: 3 months ago
JSON representation
Sample repository with code to deploy a custom Ubuntu container to AWS Lambda using the Serverless Framework.
- Host: GitHub
- URL: https://github.com/simonsfoundation/serverless-awslambda-container
- Owner: simonsfoundation
- Created: 2023-05-31T12:42:28.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2023-06-01T15:42:29.000Z (about 3 years ago)
- Last Synced: 2025-01-18T21:32:29.415Z (over 1 year ago)
- Language: Dockerfile
- Size: 3.91 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# serverless-awslambda-container
Create an AWS Lambda powered API endpoint using a custom build Ubuntu base image for ECR container.
## Getting Started
Install [serverless framework](https://www.serverless.com/framework/docs/getting-started) via NPM or as a standalone
binary.
```shell
$ sls --version
Framework Core: 3.31.0
Plugin: 6.2.3
SDK: 4.3.2
```
You should also have permissions to deploy to AWS Lambda, ECR, Cloudwatch, S3, and create IAM Lambda execution role.
Create an environment file `.env` with AWS profile infomation.
The sample `.env` file below also has environment vars necessary for currect serverless.yml.
```shell
AWS_PROFILE="my-profile-name"
AWS_REGION="us-east-1"
ENVIRON_VARIABLE_1="HelloWorld"
TAG_MANAGED_BY="email@example.com"
TAG_COST_CENTER="12345-05432"
```
## Deploy
Add AWS credentials to `~/.aws/credentials`
To build container from dockerfile and deploy to ecr for lambda
```shell
sls deploy
```
To remove everything created by serverless
```shell
sls remove
```
Make sure to save the `.serverless` directory as it contains JSON statefiles which are helpful for future updates.
## Writing the application
The Dockerfile will copy over everything in the `app` directory and install python requirements from `requirements.txt`
```dockerfile
# Copy function code
COPY ./app/ ${LAMBDA_TASK_ROOT}/
# Install function dependencies
COPY requirements.txt /
RUN pip install \
-r "/requirements.txt" \
--target "${LAMBDA_TASK_ROOT}"
```
You can add additional dependencies and build up your code within the `app` directory.
Lambda supports container images upto 10GB in size.
Best of luck!
## References
[https://aws.amazon.com/blogs/aws/new-for-aws-lambda-container-image-support/](https://aws.amazon.com/blogs/aws/new-for-aws-lambda-container-image-support/)
[https://docs.aws.amazon.com/lambda/latest/dg/images-create.html](https://docs.aws.amazon.com/lambda/latest/dg/images-create.html)
[https://aws.amazon.com/blogs/opensource/simplify-development-using-aws-lambda-container-image-with-a-serverless-framework/](https://aws.amazon.com/blogs/opensource/simplify-development-using-aws-lambda-container-image-with-a-serverless-framework/)