Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to upload a generated folder content into S3 using CodeBuild?

I am trying to configure a CodePipeline on AWS that it takes my Nuxt website on Github, run the command npm run generate to generate the static website then upload the dist folder on an S3 bucket.

Here what my buildspec.yml it looks like:

version: 0.2

phases:
  install:
    commands:
      - npm install
  build:
    commands:
      - npm run generate
  post_build:
    commands:
      - aws s3 sync dist $S3_BUCKET

The error I get is: The user-provided path dist does not exist. Is anyone know how to correct this? I read a lot about artefacts but I never use them before…

Thanks in advance,

like image 643
Sébastien Serre Avatar asked Jul 03 '26 10:07

Sébastien Serre


1 Answers

You can use artifacts to upload dist folder to s3. I will suggest not to use post build command to achieve this because the post build command runs even when the build is failed, this is the known limitation of codebuild. Just replace your buildspec with the following.

version: 0.2

phases:
  install:
    commands:
      - npm install
  build:
    commands:
      - npm run generate
artifacts:
  files:
    - '**/*'
  base-directory: 'dist'

'**/*' means it will upload all the files and folder under the base directory "dist". You need to mention your bucket name in your aws console ( browser). enter image description here Also make sure that your codebuild IAM role has sufficient permission to access your bucket.

like image 197
Mounick Avatar answered Jul 06 '26 07:07

Mounick



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!