Raghu Ram
Raghu Ram

Reputation: 137

Can't copy build artifact to S3 bucket

I was trying to copy the file generated during codebuild to S3 bucket using the cp command. I can able to see the file but when I tried to copy the file it says file not existing. I was still confused why I cant able to copy the file. Please check the Buildspec.yml below.

version: 0.2 
phases: 
  install: 
    commands: 
      - echo Installing MySQL 
      - apt update 
      - apt-get install mysql-client -y 
      - mysqldump --version
      - mysqldump -h ***** -u $User -p****--no-data --routines --triggers -f testdb > ./backup.sql 
      - ls
      - aws s3 cp backup.sql s3://dev-test --recursive --acl public-read --cache-control "max-age=100"
  post_build: 
    commands: 
      - echo Build completed on `date` 

Please check the logs generated by AWS Codebuild.

Logs:

[Container] 2021/04/26 02:55:41 Running command mysqldump -h ***** -u $User -p****--no-data --routines --triggers -f testdb > ./backup.sql

[Container] 2021/04/26 02:55:43 Running command ls
Jenkinsfile
README.md
backup.sql
buildspec.yml
utils.groovy

[Container] 2021/04/26 02:55:43 Running command aws s3 cp backup.sql s3://dev-test --recursive --acl public-read --cache-control "max-age=100"
warning: Skipping file /codebuild/output/src985236234/src/backup.sql/. File does not exist.
Completed 0 file(s) with ~0 file(s) remaining (calculating...)

[Container] 2021/04/26 02:55:44 Command did not exit successfully aws s3 cp backup.sql s3://dev-test --recursive --acl public-read --cache-control "max-age=100" exit status 2
[Container] 2021/04/26 02:55:44 Phase complete: INSTALL State: FAILED
[Container] 2021/04/26 02:55:44 Phase context status code: COMMAND_EXECUTION_ERROR Message:   Error while executing command: aws s3 cp backup.sql s3://dev-test --recursive --acl public-read --cache-control "max-age=100". Reason: exit status 2```

Upvotes: 1

Views: 1008

Answers (1)

Marcin
Marcin

Reputation: 238091

You are uploading a single file backup.sql, but --recursive will treat is as directory.

It should be:

aws s3 cp backup.sql s3://dev-test --acl public-read --cache-control "max-age=100"

Upvotes: 1

Related Questions