'How I can deploy a subfolder into my bucket's root path?

For my react App I use the following buildspec.yml to deploy a reast Single Page Application:

version: 0.2

phases:
  pre_build:
    commands:
      - npm install
  build:
    commands:
      - npm run build

cache:
  paths:
    - /root/.npm/**/*

artifacts:
  files:
    - ./build/**

I also created an s3 bucket as static website and I deploy it directly via codeploy. But the folder that is deployed is into the ./build istead of the bucket's root. Is there a way to translate the paths of the codebuild's output artifacts into the deployed paths?

The codebuild path is used as a step in a codepipeline.



Solution 1:[1]

In order to do that you must specify a base-directory then tell the codebuild to set everything as artifact. This would be your final buildspec.yml:

version: 0.2

phases:
  pre_build:
    commands:
      - npm install
  build:
    commands:
      - npm run build

cache:
  paths:
    - /root/.npm/**/*

artifacts:
  files:
    - '**/*'
  base-directory: './build'

And you also can safely delete the rogue ./build folder into your s3 bucket.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1