CodeBuild artifacts in a S3 Subfolder

Viewed 491

I'm using CodeBuild to do a basic build for a Node project.

I'm trying to set an output folder on S3 but I cannot specify a subfolder given a Bucket, I can achieve at max one level folder.

I want to put all output files in a bucket in assets/translations/ folder. enter image description here

But with this syntax CodeBuild gives me this error:

Invalid artifacts: outputName must be a valid S3 key

Can I specify in some way the subfolder in CodeBuild?

Here's my Buildspec.yml:

version: 0.2

phases:
  install:
    commands:
      - npm ci
  build:
    commands:
      - echo Build started on `date`
  post_build:
    commands:
      - npm run translate
artifacts:
  files:
    - output/*.json
  discard-paths: yes

Note: it does work when I just put assets as output folder, it works correctly

2 Answers

I had the same issue with CodeBuild.

I ended up using CodePipeline and through that UI I was able to define the S3 key that CodeBuild would not accept

Did you ever figure this out? If you didn't the first question is did you define an artifact folder? Keep in mind that code build will need to be part of a pipeline that defines an artifact folder that will essentially upload the files to the specific artifact folder you defined. If that doesn't make sense please look into building your Codepipeline, this tutorial is pretty good for that.

https://medium.com/@adrianarba/ci-cd-defined-through-terraform-using-aws-codepipeline-aws-codecommit-and-aws-codebuild-12ade4d9cfa3

To address your question, this should do it for you:

  # Artifacts
  artifacts:
    locaton            = aws_s3_bucket.myapp-project.bucket
    type               = "S3"        
    name               = "YourFilename.json"
    path               = "assets/translations/"
    packaging          = "NONE"

Reference Artifact syntax here but that should work for you

Related