Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in AWS by (19.1k points)

I'm building a project that puts all of it's files in a 'dist' folder, and running it through CodeBuild. I'm trying to get it to put all of the files and folders in 'dist' into the root of the s3 bucket, but I'm having trouble figuring out how to make that work.

My 'dist' folder looks something like this:

- index.html

- somecssfiles.css

- fonts/

- - some fonts or w/e

- js/ 

- - some javascript files

I've tried a lot of different stuff, but can't seem to get it to just drop 'dist/*' into the root of the s3 bucket. Here's the current iteration of my artifacts property in the buildspec.yml file:

artifacts:

  files:

    - '*'

  discard-paths: yes

  base-directory: 'dist'

I thought that would probably work, but it ignores the folders. Any help is appreciated, thanks for reading.

1 Answer

0 votes
by (44.4k points)

I only recently figured this out myself, so experts please forgive me if I am incorrect, but:

The "discard-paths: yes" is what throws away your directory structure. It essentially flattens your artifact set. If (like me) you only want to throw away paths up to your artifact folder, put that full path in the "base-directory" field.

Again, this part I'm not sure about, but it seemed to me that you can't tell CodeBuild not to apply server-side encryption to your artifacts, meaning if its a website you intend to allow people to browse to, that's not going to work, at least out of the box. What I ended up doing was instead of using the artifact section of codebuild at all, I added the following post_build command:

commands: - aws s3 sync my/artifact/path/ s3://my-bucket-name/

I am building using a docker image I created and added to Amazon's ECR, I had to install the AWS CLI in my image to be able to run that command.

You can read more about Amazon S3 on AWS S3.

Related questions

Want to get 50% Hike on your Salary?

Learn how we helped 50,000+ professionals like you !

0 votes
1 answer

Browse Categories

...