Serverless AWs Custom Image ECR

Hi Yall,

Referring to this article, where we can now use custom container for running Lambdas.

Serverless does a lot of the heavy lifting if our Dockerfile is simple to define. What if I need to pass in a build-arg to my docker build, for example a credential to a private artifactory repo

docker build . -t image-name --build-arg API_KEY=&&$&%&%&##

the command below does not allow me to pass in any build-args

  name: aws
    # In this section you can define images that will be built locally and uploaded to ECR
        path: ./

How would I go about this?

I would suggest using other methods to access values such as that by passing environment variables to the Lambda functions. I have not done this with docker containers yet, but I assume you can just use the environment variable support to have things like API_KEY passed into the Lambda environment instead:

Hmm, I guess I could have been more obvious about the problem.

The api key is to access a package repository from where I’m doing a pip install at build time for my docker. It’s not a runtime env key for my lambda.

The problem here is the serverless needing the Sha digest of the deployed image to ECR, which implies that the image is deployed then I do a SLS deploy, by copying the value into the serverless.yml

But I cannot have this 2 step process in a automated CICD, it needs some intervention.

1 Like

hey @alexanderluiscampino . While not optimal this is what i’m doing:

  • Have a main image (1) i build directly so i can pass build-args
  • Have another Dockerfile (2) i call Dockerfile.sls, which only does: FROM [The previous image]
  • Reference 2 in my serverless file

With this i still leverage serverless for uploading to ecr and create the lambda with the right version/digest.

It would definitively be useful to have it directly supported in the framework, have you created a feature request?
Hope this helps.

1 Like

Hi @macebalp ,

thanks for the suggestion, do you have this example on github, so I can see it? I am assuming that if you run on this on CICD, the runner that builds the 1st image keeps that layer around, so when the sls deploy happens and that 2nd docker file is used, it can pull from the image just created, since it is still around. Is that it?

Also, how do you make feature requests?