1

New'ish to AWS very new to CI/CD. And have a question re: deploying a Deploying React Website to an S3 Bucket.

I've got me a Git repo that contains a React web app.

I've setup an AWS CodePipeline project, which polls the master branch of the repo looking for commits.

It then triggers the AWS CodeBuild project which builds the react app as defined in the buildspec.yml

In the example/tutorial I've followed the buildspec.yml had the following...

post_build:
    commands:
      - aws s3 cp dist s3://${S3_BUCKET} --recursive

...which copies the build output to the destination S3 Bucket.

It all works great, however this assumes that the S3 Bucket is already there.

Question: Which step should be responsible for creating the destination S3 Bucket and what should I be using to do so?

I'm thinking that perhaps it should be a CodeDeploy with another Cloudformation Template

Just after a little guidance before going down the wrong route :)

Many thanks.

1 Answer 1

1

Ok, so I think I found the tutorial you were referring to: https://www.karelbemelmans.com/2017/01/deploying-a-hugo-website-to-amazon-s3-using-aws-codebuild/

Can you specify two post_build commands? You could just create the bucket first which might fail if the bucket already exists but who cares right? Or you could check if the bucket exists and only if it doesn't create it. Here's the s3 command you need to create a bucket:

https://docs.aws.amazon.com/cli/latest/reference/s3api/create-bucket.html

There's an API for list buckets but I can't post it because this new user doesn't have 10 reputation yet unfortunately.

Good luck, -Asaf

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.