use gitlab ci/cd to push a file to Amazon S3

akpvt

akpvt

Posted on April 1, 2023

use gitlab ci/cd to push a file to Amazon S3

The best way to use gitlab CI is to use AWS CLI docker image

You can use GitLab CI pipeline that can upload a file to AWS S3.

AWS CLI would allow you to push to S3.

Instead of build your own Docker image and publishing it somewhere, you could use official AWS provider docker image:

https://hub.docker.com/r/amazon/aws-cli

Use AWS credentials

Get an AWS IAM user with programmatic access to the S3 bucket.

Add the following variables in your GitLab CI:

  • S3_BUCKET (the name of the S3 bucket)
  • AWS_ACCESS_KEY_ID (provided by AWS)
  • AWS_SECRET_ACCESS_KEY (provided by AWS)
COPY TO S3:
  image:
    name: amazon/aws-cli
    entrypoint: [""]
  script:
    - aws configure set region us-east-1
    - touch your-file.txt
    - aws s3 cp your-file.txt s3://$S3_BUCKET/your-file.txt

Enter fullscreen mode Exit fullscreen mode
💖 💪 🙅 🚩
akpvt
akpvt

Posted on April 1, 2023

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related