blog podcast

ECR and Lambdas Step Two

Ok, so we’re in the middle of pushing lambda images to ECR in AWS. How do you push your image? Well, here’s a small script that basically does the job.

As you can see it requires the $AWS_ACCOUNT_ID and AWS_REGION from the outside, but appart from that it does the job.

Now, if you’re doing this as a hobby thing, as I am, you probably want to be conscious of how many images you upload. The charge is 0.10 $ per GB/Month, which isn’t much, but one image is about 500 MB, so you can pretty quickly run up high costs here. That’s why I consciously push everything to just a :latest tag. No need to look back anyway.

Code of the Day

#!/bin/bash

# For this script to run, you need to have set $AWS_ACCOUNT_ID and $AWS_REGION as environment variables. I recommend doing this in your ~/.bashrc, ~/.zshrc

IMAGE_NAME="dev-blog/persist-metrics-lambda"
IMAGE_VERSION=`cat package.json | jq -r '.version'`
REMOTE_FULL_NAME="$AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/$IMAGE_NAME:latest"

docker tag $IMAGE_NAME:$IMAGE_VERSION $REMOTE_FULL_NAME

aws ecr get-login-password --region $AWS_REGION | docker login --username AWS --password-stdin $AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com

docker push $REMOTE_FULL_NAME