Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Amazon cli image doesn't work with Gitlab CI

I'm trying to run the aws command (to invalidate cloudfront) using official aws image and have the following config of .gitlab-ci.yml:

static-invalidation:
  <<: *production-env
  stage: static_invalidation
  image: amazon/aws-cli:latest
  variables:
    AWS_ACCESS_KEY_ID: $CLOUDFRONT_AWS_ACCESS_KEY_ID
    AWS_SECRET_ACCESS_KEY: $CLOUDFRONT_AWS_SECRET_ACCESS_KEY
  script:
    - aws cloudfront create-invalidation --distribution-id $CLOUDFRONT_DISTRIBUTION --invalidation-batch file://deployment/configs/inv-batch.json

The job fails with the following error:

Using docker image sha256:00cf4f100b03d1b26e93cce377c1311c34efa753e379cd5c6ea5d458337cbaab for amazon/aws-cli:2.2.17 with digest amazon/aws-cli@sha256:39e9898fc43f618636a2190f82b9babcdc618d054e66b49c9959b9cd23285ade ...
usage: aws [options] <command> <subcommand> [<subcommand> ...] [parameters]
To see help text, you can run:
  aws help
  aws <command> help
  aws <command> <subcommand> help
aws: error: argument command: Invalid choice, valid choices are:
accessanalyzer                           | acm                                     
acm-pca                                  | alexaforbusiness
...
ERROR: Job failed: exit code 252

Any ideas why it's not working? When I run the command locally it works.

like image 262
vmikhieienko Avatar asked Dec 05 '25 17:12

vmikhieienko


1 Answers

amazon/aws-cli docker has set entrypoint to aws as it's expected to be executed as

$ docker run amazon/aws-cli cloudfront create-invalidation --distribution-id ...

but gitlab expects entry point to shell so it can then execute script commands.

Check out gitlab documentation: https://docs.gitlab.com/ee/ci/docker/using_docker_images.html#available-settings-for-image

You will find there how to override docker image entrypoint.


Working config is:

image:
    name: amazon/aws-cli:2.2.18
    entrypoint: [""]
like image 70
Martin Dendis Avatar answered Dec 08 '25 11:12

Martin Dendis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!