question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Use externally built docker image in multiple functions

See original GitHub issue

Description:

I would like to deploy a stack with multiple functions that use the same docker image that I build manually beforehand (not with sam build, so I did not set the template Metadata). I was basically following the example here.
Each function has a custom command, while entrypoint and working dir are the same (explicitly set due to other bugs I read about). Pseudo example:

FunctionOne:
  Type: AWS::Serverless::Function
  Properties:
    FunctionName: !Sub "function-one-${Env}"
    PackageType: Image
    ImageUri: !Sub ${Account}.dkr.ecr.${Region}.amazonaws.com/repo-name:${Tag}
    ImageConfig:
      Command: ["main.function_one"]
      EntryPoint: ["/lambda-entrypoint.sh"]
      WorkingDirectory: "/var/task/"

FunctionTwo:
  Type: AWS::Serverless::Function
  Properties:
    FunctionName: !Sub "function-two-${Env}"
    PackageType: Image
    ImageUri: !Sub ${Account}.dkr.ecr.${Region}.amazonaws.com/repo-name:${Tag}
    ImageConfig:
      Command: ["main.function_two"]
      EntryPoint: ["/lambda-entrypoint.sh"]
      WorkingDirectory: "/var/task/"

I skip sam build and sam package since the artifact is already pushed to the specified ECR repository.
When I run sam deploy (passing also the necessary override parameters), after the changeset gets created, the cloudformation events output contains the following for each function of the stack, and then it rollbacks the deploy:

Please don't provide ImageConfig when the intended function PackageType is Zip.
(Service: AWSLambdaInternal; Status Code: 400; Error Code: InvalidParameterValueException; Request ID: f7293f26-122c-4295-9332-ccaac8cede70; Proxy: null)

I tried specifying --image-repository to the same ecr repo in the template, and again duplicating it for each function resource in image_repositories in the samconfig.toml

image_repositories = [
  "FunctionOne=123456.dkr.ecr.eu-west-1.amazonaws.com/repo-name",
  "FunctionTwo=123456.dkr.ecr.eu-west-1.amazonaws.com/repo-name",
]

Observed result:

During the deploy, with --debug set, amongst the output I see

Property ImageUri of FunctionOne resource is not a URL or a local imageUnable to resolve property Endpoint: OrderedDict([(‘Fn::GetAtt’, [‘FunctionOne’, ‘Arn’])]). Leaving as is.Found Serverless function with name=‘FunctionOne’ and ImageUri=‘123456.dkr.ecr.eu-west-1.amazonaws.com/repo-name:test’

Changeset created successfully. arn:… Waiting for stack create/update to complete CloudFormation events from changeset

ResourceStatus ResourceType LogicalResourceId ResourceStatusReason
UPDATE_IN_PROGRESS AWS::Lambda::Function FunctionOne -
UPDATE_FAILED AWS::Lambda::Function FunctionOne Please don’t provide ImageConfig when the intended function PackageType is Zip.

Additional environment details (Ex: Windows, Mac, Amazon Linux etc)

  1. OS: MacOS
  2. sam --version: SAM CLI, version 1.18.1
  3. AWS region: eu-west-1

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
vmengercommented, Feb 17, 2021

Roughly the same issue here, but using Azure CloudFormationCreateOrUpdateStack rather than sam deploy (those might do the same thing down the line - not sure).

Edit: solved by deleting the old cloudformation stack, which had the lambdas still built from zips. Apparently the PackageType property cannot be updated.

2reactions
solarmosaic-kflorencecommented, Apr 10, 2021

Just ran into this. Would be nice to have a better error message as I was utterly confused (same case: migrating from a ZIP package to an image package).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Multi-stage builds - Docker Documentation
With multi-stage builds, you use multiple FROM statements in your Dockerfile. Each FROM instruction can use a different base, and each of them...
Read more >
Run multiple services in a container - Docker Documentation
Run multiple services in a container. A container's main running process is the ENTRYPOINT and/or CMD at the end of the Dockerfile ....
Read more >
Dockerfiles now Support Multiple Build Contexts | Docker
Inside a Dockerfile you can use COPY and ADD commands to copy files from your build context and make them available to your...
Read more >
docker build - Docker Documentation
The docker build command builds Docker images from a Dockerfile and a “context”. A build's context is the set of files located in...
Read more >
Set up Automated Builds - Docker Documentation
Docker Hub can automatically build images from source code in an external repository and automatically push the built image to your Docker repositories....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found