Teh__docco
Teh__docco

Reputation: 435

How can I access the shell of the AWS Lambda images on ECR

I wanted to install some dependencies for my lambda function to use. The original pipeline used the amazonlinux:2 docker image, where we install the dependencies on it and then package it and upload using serverless.

While this was working for python3.7, this is breaking for python versions >3.7 as mentioned in this GitHub issue, which says its probably because python3.8 and higher don't have amazonlinux as base image.

So I wanted to use the closest base image possible, and use public.ecr.aws/lambda/python:3.8.

I get the following error for my commands though,

docker run public.ecr.aws/lambda/python:3.9
output: entrypoint requires the handler name to be the first argument

docker run --rm \
--volumes-from src \
public.ecr.aws/lambda/python:3.8 \
/bin/bash -c "cd $(container_dir) && sh build_lambda.sh"
output:entrypoint requires the handler name to be the first argument

But a dockerfile with commands like below works when I run docker build.

FROM --platform=linux/x86_64 public.ecr.aws/lambda/python:3.8

// Set up working directories
RUN mkdir -p /opt/app
RUN mkdir -p /opt/app/build
RUN mkdir -p /opt/app/bin/
...

I want to be able to do that with shell, so running this image as a container, accessing its shell without a Dockerfile. The current pipeline puts the shell commands in build_lambda.sh and I don't want to change it too much.

Any better recommended approach would also be welcome

Upvotes: 7

Views: 2874

Answers (1)

joematune
joematune

Reputation: 2100

so running this image as a container, accessing its shell without a Dockerfile

If I understand correctly, you're looking to open a shell inside public.ecr.aws/lambda/python:3.8.

You can run:

docker run -it --entrypoint "/bin/bash" public.ecr.aws/lambda/python:3.8

You're then inside, free to run commands, which will look something like:

bash-4.2# pwd
/var/task

Upvotes: 12

Related Questions