Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mattpetters/deno2lambda
Template for Deno 2 based serverless function on AWS Lambda
https://github.com/mattpetters/deno2lambda
Last synced: about 1 month ago
JSON representation
Template for Deno 2 based serverless function on AWS Lambda
- Host: GitHub
- URL: https://github.com/mattpetters/deno2lambda
- Owner: mattpetters
- Created: 2024-10-21T15:06:02.000Z (4 months ago)
- Default Branch: main
- Last Pushed: 2024-10-21T15:34:33.000Z (4 months ago)
- Last Synced: 2024-11-09T15:05:12.484Z (3 months ago)
- Language: Shell
- Size: 8.79 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Deno 2 - AWS Lambda Template
Following the instructions here:
https://docs.deno.com/runtime/tutorials/aws_lambda/
Reproducing some of those docs here for convenience but if you have any issues reference the docs
Leverages the `aws-lambda-adapter` and docker
## Deploy
1. Build the docker image
```bash
docker build -t hello-world .
```2. Create the ECR repository + push (note: change region as needed)
```bash
AWS_REGION=us-west-2
aws ecr create-repository --repository-name hello-world --region $AWS_REGION | grep repositoryUri```
This should output a repository URI that looks like .dkr.ecr.us-west-2.amazonaws.com/hello-world.
then:
```bash
aws ecr get-login-password --region $AWS_REGION | docker login --username AWS --password-stdin .dkr.ecr.us-west-2.amazonaws.com
```Tag the Docker image with the repository URI, again using the repository URI from the previous steps:
```bash
docker tag hello-world:latest .dkr.ecr.us-west-2.amazonaws.com/hello-world:latest
```Finally, push the Docker image to the ECR repository, using the repository URI from the previous steps:
```bash
docker push .dkr.ecr.us-west-2.amazonaws.com/hello-world:latest```
## Step 5: Create an AWS Lambda function
Now you can create a new AWS Lambda function from the AWS Management Console.
1. Go to the AWS Management Console and navigate to the Lambda service.
2. Click on the "Create function" button.
3. Choose "Container image".
4. Enter a name for the function, like "hello-world".
5. Click on the "Browse images" button and select the image you pushed to ECR.
6. Click on the "Create function" button.
7. Wait for the function to be created.
8. In the "Configuration" tab, go to the "Function URL" section and click on "Create function URL".
9. Choose "NONE" for the auth type (this will make the lambda function publicly accessible).
10. Click on the "Save" button.## Step 6: Test the Lambda function Jump to heading#
- You can now visit your Lambda function's URL to see the response from your Deno app.- 🦕 You have successfully deployed a Deno app to AWS Lambda using Docker. You can now use this setup to deploy more complex Deno apps to AWS Lambda.
# Helper scripts/monorepo structure for multiple functions
- First time through creating the function use the steps above
- after that, you can use the deploy helper:
- `deploy.sh` - deploys the function to AWS Lambda, just pass the folder name as an argument
- to add a new function, copy the folder and change the dockerfile as needed
- NOTE: AWS region `us-west-2` is hardcoded in the deploy script, change as needed