Create the pipeline
Source and Build from the wizard, then add the deploy stage with its own CodeBuild project.
About 30 min · Verified 8 October 2026
You build this pipeline in two passes. The wizard creates Source and Build. Then you edit the pipeline to add a DeployWeb stage, because the wizard's Deploy step cannot run aws s3 sync --delete with your cache headers, but a CodeBuild project can.
Pass 1: the wizard#
Pipeline settings#
Open CodePipelinePipelinesCreate pipeline, choose Build custom pipeline, Next.
| Field | Value |
|---|---|
| Pipeline name | shortlink-web-prod |
| Pipeline type | V2 |
| Execution mode | Queued |
| Service role | New service role |
Leave the artifact store on Default location. It is a private codepipeline-<region>-… bucket, not your website bucket. Choose Next.
Source#
| Field | Value |
|---|---|
| Source provider | GitHub (via GitHub App) |
| Connection | shortlink-github |
| Repository name | <GITHUB_USER>/shortlink (your fork) |
| Default branch | main |
| Output artifact format | CodePipeline default |
Under Trigger keep Start the pipeline on source code change and add:
| Field | Value |
|---|---|
| Event type | Push |
| Branches → Include | main |
| File paths → Include | shortlink-web/**, deploy/buildspec-web.yml, deploy/buildspec-web-deploy.yml |
Only commits that change the website or its buildspecs publish a new site. Choose Next.
Build: create shortlink-web-build#
| Field | Value |
|---|---|
| Build provider | Other build providers → AWS CodeBuild |
| Region | ap-south-1 |
| Project name | Create project |
In the CodeBuild form:
| Field | Value |
|---|---|
| Project name | shortlink-web-build |
| Project type | Default project |
| Environment image | Managed image |
| Compute | EC2 |
| Operating system / Runtime | Amazon Linux / Standard |
| Image | aws/codebuild/amazonlinux-x86_64-standard:5.0 (or the newest standard image) |
| Compute size | 3 GB memory, 2 vCPUs or larger (the reference setup used medium) |
| Service role | New service role |
| Buildspec | Use a buildspec file → deploy/buildspec-web.yml |
| Logs | CloudWatch logs ticked |
Open Additional configuration and add the environment variable that tells the site where the API is:
| Name | Value | Type |
|---|---|---|
VITE_API_BASE_URL | <API_URL> | Plaintext |
Choose Continue to CodePipeline. Check Input artifacts is SourceArtifact, Build type is Single build, and leave the output artifact as BuildArtifact. Choose Next.
Test and Deploy: skip both#
Choose Skip test stage, then Skip deploy stage (confirm each). Choose Create pipeline.
The pipeline runs Source → Build once. When Build is green, you have a working build. Nothing is published yet.
Pass 2: add the deploy stage#
Edit the pipeline and add a stage#
Open the pipeline and choose Edit. Under the Build stage choose + Add stage, name it DeployWeb, and Add stage. In the new stage choose + Add action group.
Configure the WebDeploy action#
| Field | Value |
|---|---|
| Action name | WebDeploy |
| Action provider | AWS CodeBuild (listed under Build) |
| Region | ap-south-1 |
| Input artifacts | BuildArtifact |
| Project name | Create project |
In the CodeBuild form:
| Field | Value |
|---|---|
| Project name | shortlink-web-deploy |
| Project type | Default project |
| Environment | same as the build project: managed image, EC2, Amazon Linux, Standard, 5.0 |
| Compute size | the smallest is fine |
| Service role | New service role |
| Buildspec | Use a buildspec file → deploy/buildspec-web-deploy.yml |
| Environment variables | none |
Choose Continue to CodePipeline, set Build type to Single build, leave Output artifacts empty, and choose Done. Then Done on the stage, and Save the pipeline (confirm).
Verify the structure#
aws codepipeline get-pipeline --region ap-south-1 --name shortlink-web-prod \
--query 'pipeline.stages[].{stage:name,actions:actions[].{action:name,provider:actionTypeId.provider,project:configuration.ProjectName,in:inputArtifacts[].name,out:outputArtifacts[].name}}' \
--output jsonshortlink-web-build, in SourceArtifact, out BuildArtifact) → DeployWeb (WebDeploy, shortlink-web-deploy, in BuildArtifact, no output).Confirm both CodeBuild projects run in pipeline mode:
aws codebuild batch-get-projects --region ap-south-1 --names shortlink-web-build shortlink-web-deploy \
--query 'projects[].{name:name,source:source.type,artifacts:artifacts.type,buildspec:source.buildspec,webhook:webhook.url}' --output tablesource and artifacts must both be CODEPIPELINE and webhook must be empty. Projects created from inside the pipeline editor are right already.
My CodeBuild projects show GitHub as the source, or a webhook is set
That happens when a project was created in the CodeBuild console on its own, before being added to the pipeline. A direct webhook would also start builds that bypass the pipeline. Remove it and switch the types:
aws codebuild delete-webhook --region ap-south-1 --project-name shortlink-web-deploy
aws codebuild update-project --region ap-south-1 --name shortlink-web-build \
--source 'type=CODEPIPELINE,buildspec=deploy/buildspec-web.yml' --artifacts 'type=CODEPIPELINE'
aws codebuild update-project --region ap-south-1 --name shortlink-web-deploy \
--source 'type=CODEPIPELINE,buildspec=deploy/buildspec-web-deploy.yml' --artifacts 'type=CODEPIPELINE'Skip delete-webhook if the project has no webhook. Note that the deploy project needs artifacts of type CODEPIPELINE too, even though it produces no output: CodeBuild checks source and artifact types together and rejects NO_ARTIFACTS when the source is CODEPIPELINE.
Found a mistake? Edit this page on GitHub.