AWS SAM Deploy Missing option '--image-repository' or '--image-repositories'
Asked by Han:

Hi all,

I am trying to deploy to Lambda using \`aws-sam-deploy\` pipe and got an "Missing option '--image-repository' or '--image-repositories'" error when packaging. However, I have included "image_repositories" inside my \`samconfig.toml\` file and set SAM_CONFIG to \`samconfig.toml\` file.

I can build and deploy to AWS Lambda using Docker images from local without any problems with the command \`sam build\` and then \`sam deploy\`. So I do not think there's anything wrong with my \`template.yaml\` or \`samconfig.toml\`

What steps am I missing? Any help would be greatly appreciated.

Thank you!!

HCL

bitbucket-pipeline error message:

INFO: Using default authentication with AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY.

INFO: Start package...` `

SAM CLI now collects telemetry to better understand customer needs.` `

You can OPT OUT and disable telemetry collection by setting the environment variable SAM_CLI_TELEMETRY=0 in your shell. Thanks for your help! Learn More: <https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-telemetry.html>

Usage: sam package [OPTIONS]

Try 'sam package -h' for help.

Error: Missing option '--image-repository' or '--image-repositories'

? Failed SAM package.

Relevant part of my pipeline (monorepo, so I have to cd into the specific directory where \`samconfg.toml\` and \`template.yaml\` resides:

```
          script:
            - apt-get update
            - cd project/function
            - pipe: atlassian/aws-sam-deploy:1.2.0
              variables:
                AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID
                AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY
                AWS_DEFAULT_REGION: $AWS_DEFAULT_REGION
                S3_BUCKET: 'lambda-function-bucket'
                STACK_NAME: 'MyLambdaFunction'
                CAPABILITIES: ['CAPABILITY_IAM']
                SAM_TEMPLATE: 'template.yaml'
                SAM_CONFIG: "samconfig.toml"
                WAIT: 'true'
                WAIT_INTERVAL: 60
```

And here's my samconfig.toml:

````
```

version = 0.1
[default]
[default.deploy]
[default.deploy.parameters]
stack_name = "MyLambdaFunction"
s3_bucket = "lambda-function-bucket"
s3_prefix = "s3-prefix/"
region = "us-east-1"
capabilities = "CAPABILITY_IAM"
image_repositories = ["MyLambdaFunction=12345678910.dkr.ecr.us-east-1.amazonaws.com/my-lambda-function"]
confirm_changeset = false
````


Answers:
author: Halyna Berezovska
body: [@Han](/t5/user/viewprofilepage/user-id/4447377) In our pipe we are using sam package firstly.

```
image_repositories
```

parameter is in deploy section, not in package. I guess, it should be in both ones, since the command failed is \`sam package\`, not sam deploy .

However, if you don't want to use sam package, you can always use deploy command only. Be aware that for deploy that we don't support toml sam config yet.

Regarding aws lambda container image support, we are working on this right now (in aws-lambda-deploy pipe)

Regards, Galyna

comments: author: Han
body: Hi [@Halyna Berezovska](/t5/user/viewprofilepage/user-id/3865505) ,  

If I understand you correctly, \`image_repositories\` has to be specified in both \`aws-lambda-deploy\` pipe and \`samconfig.toml\`?

I am deploying to Lambda using Docker images manually at the moment. When do you expect \`aws-lambda-deploy\` to support AWS Lambda container image deployment to be done?

Also, how do I use the deploy command only and what do I need to do to successfully deploy to Lambda from Docker Images?


author: Halyna Berezovska
body: [@Han](/t5/user/viewprofilepage/user-id/4447377) Unfortunately, right now in aws-sam-deploy we don't support images yet.

As a temporary workaround I suggest using sam package with proper config and sam deploy in bitbucket-pipelines without using aws-sam-deploy pipe.

This is to create function.

For update function, basically we use aws-lambda-deploy pipe, but it also does not support images yet.

I suspect you would prefer aws-sam-deploy pipe, where you have samconfig and you would like this samconfig to be support for packaging and deploying.

This is nice improvement and I'll discuss it within the team and notify you with update.

For now I suggest using aws sam cli (we recommend to follow their installation - downloading binary <https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install-linux.html#serverless-sam-cli-install-linux-sam-cli>)

Regards, Galyna


author: Han
body: [@Halyna Berezovska](/t5/user/viewprofilepage/user-id/3865505)

Correct. I would like to have alignment between both manual \`sam deploy\` and CD via aws-sam-deploy pipe.  

AWS just released and AWS SAM Pipelines that generates support for serveless applications, image or otherwise. <https://aws.amazon.com/blogs/compute/introducing-aws-sam-pipelines-automatically-generate-deployment-pipelines-for-serverless-applications/>. Unfortunately, it only supports Jenkins, GitHub, and GitLab.  

When can I expect Bitbucket to reach feature parity with this?  

HCL


author: Daniel Coppell
body: "I suspect you would prefer aws-sam-deploy pipe, where you have samconfig and you would like this samconfig to be support for packaging and deploying."

This would be an excellent feature. I haven't been able to use the aws-sam-deploy pipe thus far because it's useless to me without accepting a samconfig toml file for the deploy command. Currently I have to use custom images with the AWS SAM CLI installed which are rather large and increase my build time.

If there's an issue link or a roadmap available with this feature on it I'd love a link so I can come back and check periodically to see if this feature has been added.

I wonder how anyone using this pipe is avoiding getting errors without the  
--no-fail-on-empty-changeset option available? CI/CD pipelines surely hit the "Error: No changes to deploy. Stack stack-name is up to date'." error all the time?


author: Han
body: Solved using AWS SAM CLI directly. [@Daniel Coppell](/t5/user/viewprofilepage/user-id/4518372)

FYI, deployment time is highly dependent the size of the docker image, but I find it faster than my local machine probably from higher bandwidth connection to AWS

```
- step:
  name: CD
  caches:
    - pip
  script:
    - apt-get update
    - pip install awscli
    - pip install aws-sam-cli
    - aws configure --profile cicd set AWS_ACCESS_KEY_ID ${AWS_ACCESS_KEY_ID}
    - aws configure --profile cicd set AWS_SECRET_ACCESS_KEY ${AWS_SECRET_ACCESS_KEY}
    - sam build --profile cicd
    - sam deploy --profile cicd
  services:
    - docker
```


Tags: aws

bitbucket-pipelines

deployment