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

akpvt - Apr 1 '23 - - Dev Community

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
. . . . . . . . . . . . . . . . .
Terabox Video Player