Skip to content

Instantly share code, notes, and snippets.

@Graham-Beer
Forked from vfarcic/04-05-lambda-container.sh
Created February 5, 2023 12:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Graham-Beer/9a48f424ba271dd3f300db7db89a5a28 to your computer and use it in GitHub Desktop.
Save Graham-Beer/9a48f424ba271dd3f300db7db89a5a28 to your computer and use it in GitHub Desktop.
# Source: https://gist.github.com/7e0ada996b5d09486f2df0d7e1cbbea2
###############################################
# Amazon Lambda Containers #
# Packaging AWS Functions as Container Images #
# https://youtu.be/DsQbBVr-GwU #
###############################################
# Requirements:
# - AWS account (https://aws.amazon.com/)
# - `aws` CLI (https://aws.amazon.com/cli/)
# - AWS config or env. vars with access keys and the default region
# - Docker (https://www.docker.com/)
# ... or ...
# - Gitpod with the Chrome extension (https://youtu.be/QV1fYt-7SLU)
# - Environment variables *AWS_ACCESS_KEY_ID*, *AWS_SECRET_ACCESS_KEY*, and *AWS_DEFAULT_REGION* (https://gitpod.io/settings/)
# - Gitpod *Feature Preview* enabled
# Open https://github.com/vfarcic/lambda-container-demo
# Fork it
# Click the *Gitpod* button
# ECR public repository: https://gallery.ecr.aws/
docker image build \
--tag lambda-container-demo:0.0.1 \
$PWD
docker container run \
--publish 9000:8080 \
lambda-container-demo:0.0.1
curl \
"http://localhost:9000/2015-03-31/functions/function/invocations" \
-d '{"name":"Viktor"}' && echo
exit
aws ecr create-repository \
--repository-name lambda-container-demo \
--image-scanning-configuration scanOnPush=true
export REPO_URI=[...]
aws ecr get-login-password \
| docker login \
--username AWS \
--password-stdin \
$REPO_URI
docker image tag lambda-container-demo:0.0.1 \
$REPO_URI:0.0.1
docker image tag lambda-container-demo:0.0.1 \
$REPO_URI:latest
docker image push $REPO_URI:0.0.1
docker image push $REPO_URI:latest
docker image ls
# AWS Lambda: https://console.aws.amazon.com/lambda/home
export PAYLOAD=$(\
echo '{"name":"Viktor"}' | base64)
aws lambda invoke \
--function-name lambda-container-demo \
--payload $PAYLOAD \
response.json
cat response.json && echo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment