AWS CodeBuild
User Guide (API Version 2016-10-06)

A new console design is available for this service. Although the procedures in this guide were written for the older version of the console, you will find many of the concepts and basic procedures in this guide still apply.

Create a Static Website with Build Output Hosted in an Amazon S3 Bucket.

You can disable the encryption of artifacts in a build. You might want to do this so that you can publish artifacts to a location that is configured to host a website. (You cannot publish encrypted artifacts.) This sample shows how you can use webhooks to trigger a build and publish its artifacts to an Amazon S3 bucket that is configured to be a website.

  1. Follow the instructions in Setting Up a Static Website to configure an Amazon S3 bucket to function like a website.

  2. Open the AWS CodeBuild console at https://console.aws.amazon.com/codebuild/.

  3. If a welcome page is displayed, choose Get started. Otherwise, on the navigation pane, choose Build projects, and then choose Create project.

  4. On the Configure your project page, for Project name, type a name for this build project. Build project names must be unique across each AWS account.

  5. In Source: What to build, for Source provider, choose GitHub. Follow the instructions to connect (or reconnect) with GitHub and choose Authorize.

    For Webhook, select the Rebuild every time a code change is pushed to this repository check box. You can select this check box only if, under Repository, you chose Use a repository in my account.

  6. In Environment: How to build:

    For Environment image, do one of the following:

    • To use a Docker image managed by AWS CodeBuild, choose Use an image managed by AWS CodeBuild, and then make selections from Operating system, Runtime, and Version.

    • To use another Docker image, choose Specify a Docker image. For Custom image type, choose Other or Amazon ECR. If you choose Other, then for Custom image ID, type the name and tag of the Docker image in Docker Hub, using the format repository-name/image-name:image-tag. If you choose Amazon ECR, then use Amazon ECR repository and Amazon ECR image to choose the Docker image in your AWS account.

    For Build specification, do one of the following:

    • Use the buildspec.yml file in the source code root directory.

    • Override the build specification by inserting build commands.

    For more information, see the Build Spec Reference.

  7. In Artifacts: Where to put the artifacts from this build project, for Type, choose Amazon S3 to store the build output in an Amazon S3 bucket.

  8. Select Disable artifacts encryption.

  9. For Bucket name, choose the name of the output bucket you created in step 1.

  10. If you chose Insert build commands in Environment: How to build, then for Output files, enter the locations of the files from the build that you want to put into the output bucket. If you have more than one location, use a comma to separate each location (for example, "appspec.yml, target/my-app.jar").

  11. In Service role, do one of the following:

    • If you do not have an AWS CodeBuild service role, choose Create a service role in your account. In Role name, accept the default name or enter your own.

    • If you have an AWS CodeBuild service role, choose the option to use an existing role. In Role name, choose the service role.

    Note

    When you use the console to create or update a build project, you can create an AWS CodeBuild service role at the same time. By default, the role works with that build project only. If you use the console to associate this service role with another build project, the role is updated to work with the other build project. A service role can work with up to 10 build projects.

  12. Expand Show advanced settings and set them as appropriate.

  13. Choose Continue. On the Review page, choose Save and build or, to run the build later, choose Save.

  14. (Optional) Follow the instructions in Example: Speed Up Your Website with Amazon CloudFront.