Skip to content
This repository was archived by the owner on Nov 4, 2022. It is now read-only.

Commit 82fe67c

Browse files
brianzmattddiamondhakansonferdingler
authored
Update to use SAM Pipelines (#90)
* Sam pipelines (#80) * Updated bootstrap script for Amazon Linux 2 * Update setup instructions for AL2 Why --- - Some instructions needed updating for the AL2 bootstrap script How --- - Using text code snippets is simpler and easier to update than screenshots. - Update the boostrap steps with the new behavior of `bootstrap.sh` on AL2 Next Steps ---------- - Cleanup/remove old screenshots - Add steps and instructions to use SAM Pipelines * Updates to include SAM Pipelines - Added Chapter 4 which covers SAM Pipelines - Updated Formatting - Removing/updating some screenshots Co-authored-by: Matt Diamond <matt.d.diamond@hotmail.com> * feat(csharp): add csharp workshop content * fix(csharp): update setup links * Added codeowners file * renamed codeowners file * SAM Pipeline updates and reuse Hugo content What ----- - SAM Pipelines needed some better explaining and diagrams - There are many sections that are the same between languages. Create a custom Hugo snippet to share templates across languages. How ---- - Add in-depth explanation and walk through of SAM Pipelines - Update many other sections with minor copy edits and formatting. - Removed all references to the CDK build steps - Move _many_ screenshots to plain text, which will be easier to update and maintain - Update `bootstrap.sh` to work with AL2 Next ------ - Finish the canary deployment for JS. Update the SAM/CFN template to only use gradual deployment only for production stack. - Left off at the Rolbacks sections. Finish off that one and show how ,with the canary deployment enabled only on `prod`, the dev stack is updated but prod is rolled back. - Remove outdated files in other languages - Double check all of the menus for different languages and make sure they align - In further-future, it would makse sense to move to a _single_ workshop with one set of steps, and treat each language different in the same section so students could follow their language of choice within a single part of the lab. This would make maintainability much easier, and the flow of the workshop improved. - Update the cleanup steps * Add section on enabling unit tests * Updates for Python version. Why --- - Get the Python pipeline section more in-line with the JS version. How --- - Remove legacy section from Python - Update bootstrap script to work around a new error during updating. - Add a `.gitignore` step Next Steps ---------- - * Updated testing instructions for python * update tests instructions for all languages * Update canary steps with different config for dev/prod * one small fix for python3.7 * Add c# and java unit test instructions * Use latest version of learn theme * Updates to get Python/Node into one flow Why --- - Maintaining four languages is a lot of overhead. Having a single flow of the workshop using tabs where appropriate is much simpler. How --- - Use `tabs` to split Python/Node specifics, for the Lambda function - Update lots of content for accuracy - Update some screenshots * Update section on auto rollback * Move to a single set of instructions for Python/Node * Update internal reference * Finish the cleanup section * Update to metadata, README and add appendix * Update codeowner to GH username Co-authored-by: Matt Diamond <matt.d.diamond@hotmail.com> Co-authored-by: Kevin Hakanson <kevhak@amazon.com> Co-authored-by: Fernando Dingler <fdingler@amazon.com>
1 parent dc04dca commit 82fe67c

File tree

305 files changed

+2660
-7563
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

305 files changed

+2660
-7563
lines changed

CODEOWNERS

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# This is a comment.
2+
# Each line is a file pattern followed by one or more owners.
3+
4+
# These owners will be the default owners for everything in
5+
# the repo. Unless a later match takes precedence,
6+
# Owners will be requested for review when someone opens a PR.
7+
8+
* @brianz @ferdingler

README.md

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11
# CI/CD for Serverless Applications Workshop
22

3-
In this workshop, you will learn how to start a new Serverless application from scratch using the AWS Serverless Application Model (AWS SAM) and how to fully automate builds and deployments by building a continous delivery pipeline using the AWS CDK. You will also learn how to run a Serverless application locally using the SAM CLI.
3+
In this workshop, you will learn how to start a new Serverless application from scratch using the
4+
AWS Serverless Application Model (AWS SAM) and how to fully automate builds and deployments. You
5+
will bootstrap a fully-automated CI/CD pipeline using
6+
[SAM Pipelines](https://aws.amazon.com/blogs/compute/introducing-aws-sam-pipelines-automatically-generate-deployment-pipelines-for-serverless-applications/).
7+
At the end of the workshop you will have a self-updating pipeline which
8+
9+
1. Deploys two stages, `dev` and `prod`
10+
1. Runs unit tests
11+
1. Deploys gradually using canary deployments
12+
1. Monitors for errors
13+
1. Aborts deployments when errors occur
14+
15+
You will also learn how to run a Serverless application locally using the SAM CLI
416

517
![Image](workshop/static/images/github-home.svg)
618

@@ -10,12 +22,15 @@ Visit the workshop on this URL: [https://cicd.serverlessworkshops.io](https://ci
1022

1123
## Older workshop versions
1224

13-
This workshop has been evolving thanks to community contributions, but we are keeping older versions in case you prefer them. Every major update, we create a branch with the old version and we make it available in the following URLs, so feel free to use them:
25+
This workshop has been evolving thanks to community contributions. We keep older versions for those
26+
who prefer different approaches for creating CI/CD pipelines.
27+
Every major update, we create a branch with the old version and make it available in the following URLs:
1428

1529
| Version | Description | URL |
1630
| ------------- | ------------- | ------------- |
1731
| v1 | Raw cloudformation, no CDK | [https://v1.cicd.serverlessworkshops.io](https://v1.cicd.serverlessworkshops.io) |
1832
| v2 | No multi-language, javascript only | [https://v2.cicd.serverlessworkshops.io](https://v2.cicd.serverlessworkshops.io) |
33+
| v3 | CDK, without SAM Pipelines | [https://v3.cicd.serverlessworkshops.io](https://v3.cicd.serverlessworkshops.io) |
1934

2035
## Want to contribute?
2136

amplify.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ frontend:
33
phases:
44
build:
55
commands:
6-
- git clone --branch 2.4.0 https://github.com/matcornic/hugo-theme-learn.git workshop/themes/learn
6+
- git clone --depth=1 https://github.com/matcornic/hugo-theme-learn.git workshop/themes/learn
77
- hugo --source workshop --destination ../public --quiet
88
artifacts:
99
baseDirectory: /public

metadata.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,28 @@ title: CI/CD for Serverless Applications
55
#description - A short description that will be displayed in search results
66
description: In this workshop, you will learn how to start a new Serverless application from scratch using the AWS Serverless Application Model (AWS SAM) and how to fully automate builds and deployments by building a continous delivery pipeline using AWS CodeCommit, AWS CodeBuild and AWS CodePipeline. You will also learn how to test a Serverless application locally using the SAM CLI.
77
#categories - Refer to official AWS categories covered by the workshop content here
8-
categories:
8+
categories:
99
- Serverless
1010
- Lambda
1111
- Continous Delivery
1212
- Automation
1313
- SAM
1414
#services - Refer to the official AWS service names covered by the workshop content here
15-
services:
15+
services:
1616
- API Gateway
1717
- Lambda
1818
- CodePipeline
1919
- CodeCommit
2020
- CodeBuild
2121
- CloudFormation
2222
#level - Approximate skill level needed for this workshop
23-
level: 300
23+
level: 300
2424
#duration - Estimated duration in minutes
25-
duration: 120
25+
duration: 120
2626
#cost - Cost in USD. If the content is offered without cost, enter 0
27-
cost: 0
27+
cost: 0
2828
#author - Amazon alias of the primary author of the content
29-
author: fdingler
29+
author: zambb
3030
#audience - Names of the personas associated with this workshop
31-
audience:
32-
- Developer
31+
audience:
32+
- Developer

workshop/config.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pygmentsStyle = "monokai"
1616
[params]
1717
editURL = "https://github.com/aws-samples/aws-serverless-cicd-workshop/tree/master/workshop/content/"
1818
description = "Building a CI/CD pipeline for Serverless applications"
19-
author = "Fernando Dingler <fdingler@amazon.com>"
19+
author = "Brian Zambrano <zambb@amazon.com"
2020
disableBreadcrumb = false
2121
disableNextPrev = false
2222
themeVariant = "aws"
@@ -37,4 +37,4 @@ hrefTargetBlank = true
3737
[Languages.en]
3838
title = ""
3939
weight = 1
40-
languageName = "English"
40+
languageName = "English"

workshop/content/_index.en.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,21 @@ title = "CI/CD for Serverless Applications"
33
chapter = true
44
weight = 1
55
+++
6+
67
# CI/CD for Serverless Applications
78

8-
In this workshop, you will learn how to start a new Serverless application from scratch using the AWS Serverless Application Model (AWS SAM) and how to fully automate builds and deployments by building a continous delivery pipeline using the AWS CDK. You will also learn how to run a Serverless application locally using the SAM CLI.
9+
In this workshop, you will learn how to start a new Serverless application from scratch using the
10+
AWS Serverless Application Model (AWS SAM) and how to fully automate builds and deployments.
11+
You will use a feature of SAM called SAM Pipelines to bootstrap a continous delivery pipeline. You
12+
will also learn how to run a serverless application locally using the SAM CLI.
913

1014
![Intro](/images/github-home.svg)
1115

1216
### Issues, Comments, Feedback?
1317

14-
I’m open source! If you see an issue, want to contribute content, or have overall feedback please open an issue or pull request in our GitHub repository: [github.com/aws-samples/aws-serverless-cicd-workshop](https://github.com/aws-samples/aws-serverless-cicd-workshop).
15-
18+
I’m open source! If you see an issue, want to contribute content, or have overall feedback please
19+
open an issue or pull request in our GitHub repository:
20+
[github.com/aws-samples/aws-serverless-cicd-workshop](https://github.com/aws-samples/aws-serverless-cicd-workshop).
1621

1722
{{% button href="https://github.com/aws-samples/aws-serverless-cicd-workshop/issues" icon="fas fa-bug" %}}Report an issue{{% /button %}}
18-
{{% button href="https://aws.amazon.com/serverless/developer-tools" icon="fas fa-graduation-cap" %}}Learn more{{% /button %}}
23+
{{% button href="https://aws.amazon.com/serverless/developer-tools" icon="fas fa-graduation-cap" %}}Learn more{{% /button %}}
Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
+++
2+
title = "Appendix"
3+
date = 2020-07-06T17:49:47-04:00
4+
weight = 1000
5+
pre = "<b>7. </b>"
6+
+++
7+
8+
Prior versions of this workshop used the AWS CDK to create the CI/CD pipeline. CDK is a fantastic
9+
tool! If you are looking for the CDK version, below is an example CI/CD pipeline in TypeScript using
10+
CDK V2.
11+
12+
Note that this example from `v3` of this workshop is missing a few features compared to the one setup by
13+
SAM Pipelines. It does not have a specific unit test phase and does not self-update.
14+
15+
```typescript
16+
import { Stack, StackProps } from "aws-cdk-lib"
17+
import { Construct } from "constructs"
18+
19+
import * as codebuild from "aws-cdk-lib/aws-codebuild"
20+
import * as codecommit from "aws-cdk-lib/aws-codecommit"
21+
import * as codepipeline from "aws-cdk-lib/aws-codepipeline"
22+
import * as codepipeline_actions from "aws-cdk-lib/aws-codepipeline-actions"
23+
import * as s3 from "aws-cdk-lib/aws-s3"
24+
25+
export class ServerlessCicdPipelineStack extends Stack {
26+
constructor(scope: Construct, id: string, props?: StackProps) {
27+
super(scope, id, props)
28+
29+
const artifactsBucket = new s3.Bucket(this, "ArtifactsBucket")
30+
31+
const codeRepo = codecommit.Repository.fromRepositoryName(this, "AppRepository", "sam-app")
32+
// Pipeline creation starts
33+
const pipeline = new codepipeline.Pipeline(this, "Pipeline", {
34+
artifactBucket: artifactsBucket,
35+
})
36+
37+
// Declare source code as an artifact
38+
const sourceOutput = new codepipeline.Artifact()
39+
40+
// Add source stage to pipeline
41+
pipeline.addStage({
42+
stageName: "Source",
43+
actions: [
44+
new codepipeline_actions.CodeCommitSourceAction({
45+
actionName: "CodeCommit_Source",
46+
repository: codeRepo,
47+
output: sourceOutput,
48+
branch: "main",
49+
}),
50+
],
51+
})
52+
53+
// Declare build output as artifacts
54+
const buildOutput = new codepipeline.Artifact()
55+
56+
// Declare a new CodeBuild project
57+
const buildProject = new codebuild.PipelineProject(this, "Build", {
58+
environment: { buildImage: codebuild.LinuxBuildImage.AMAZON_LINUX_2_2 },
59+
environmentVariables: {
60+
PACKAGE_BUCKET: {
61+
value: artifactsBucket.bucketName,
62+
},
63+
},
64+
})
65+
66+
// Add the build stage to our pipeline
67+
pipeline.addStage({
68+
stageName: "Build",
69+
actions: [
70+
new codepipeline_actions.CodeBuildAction({
71+
actionName: "Build",
72+
project: buildProject,
73+
input: sourceOutput,
74+
outputs: [buildOutput],
75+
}),
76+
],
77+
})
78+
79+
// Prod stage
80+
pipeline.addStage({
81+
stageName: "Dev",
82+
actions: [
83+
new codepipeline_actions.CloudFormationCreateReplaceChangeSetAction({
84+
actionName: "CreateChangeSet",
85+
templatePath: buildOutput.atPath("packaged.yaml"),
86+
stackName: "sam-app-dev",
87+
adminPermissions: true,
88+
changeSetName: "sam-app-dev-changeset",
89+
runOrder: 1,
90+
}),
91+
new codepipeline_actions.CloudFormationExecuteChangeSetAction({
92+
actionName: "Deploy",
93+
stackName: "sam-app-dev",
94+
changeSetName: "sam-app-dev-changeset",
95+
runOrder: 2,
96+
}),
97+
],
98+
})
99+
100+
// Production stage
101+
pipeline.addStage({
102+
stageName: "Prod",
103+
actions: [
104+
new codepipeline_actions.CloudFormationCreateReplaceChangeSetAction({
105+
actionName: "CreateChangeSet",
106+
templatePath: buildOutput.atPath("packaged.yaml"),
107+
stackName: "sam-app-prod",
108+
adminPermissions: true,
109+
changeSetName: "sam-app-prod-changeset",
110+
runOrder: 1,
111+
}),
112+
new codepipeline_actions.CloudFormationExecuteChangeSetAction({
113+
actionName: "Deploy",
114+
stackName: "sam-app-prod",
115+
changeSetName: "sam-app-prod-changeset",
116+
runOrder: 2,
117+
}),
118+
],
119+
})
120+
}
121+
}
122+
```
123+
124+
The following `buildspec.yml` file shows how to build and test a Node AWS SAM application with the
125+
pipeline above. It's possible to extract the test command into it's own pipeline stage so that tests
126+
are run once rather than per-stage.
127+
128+
```yaml
129+
# sam-app/buildspec.yml
130+
version: 0.2
131+
phases:
132+
install:
133+
runtime-versions:
134+
nodejs: 12
135+
commands:
136+
# Install packages or any pre-reqs in this phase.
137+
# Upgrading SAM CLI to latest version
138+
- pip3 install --upgrade aws-sam-cli
139+
- sam --version
140+
- cd hello-world
141+
- npm install
142+
143+
pre_build:
144+
commands:
145+
- npm run test
146+
147+
build:
148+
commands:
149+
# Use Build phase to build your artifacts (compile, etc.)
150+
- cd ..
151+
- sam build
152+
153+
post_build:
154+
commands:
155+
# Use Post-Build for notifications, git tags, upload artifacts to S3
156+
- sam package --s3-bucket $PACKAGE_BUCKET --output-template-file packaged.yaml
157+
158+
artifacts:
159+
discard-paths: yes
160+
files:
161+
# List of local artifacts that will be passed down the pipeline
162+
- packaged.yaml
163+
```
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
+++
2+
title = "Build the pipeline"
3+
date = 2019-10-03T14:25:05-07:00
4+
weight = 25
5+
chapter = true
6+
pre = "<b>4. </b>"
7+
+++
8+
9+
# Build the pipeline
10+
11+
In this chapter you are going to learn how to automate the build, package and deploy commands by
12+
creating a continous delivery pipeline using AWS Code Pipeline. We will be using [SAM
13+
Pipelines](https://aws.amazon.com/blogs/compute/introducing-aws-sam-pipelines-automatically-generate-deployment-pipelines-for-serverless-applications/)
14+
to generate and a self-updating, multi-stage CI/CD pipeline.
15+
16+
![SimplePipeline](/images/pipeline-art.png)
17+
18+
The services used in this chapter, via SAM Pipelines are CodeCommit, CodeBuild, CodePipeline and
19+
CloudFormation.

workshop/content/java/buildpipe/credhelper/_index.en.md renamed to workshop/content/buildpipe/credhelper/_index.en.md

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,27 @@ weight = 10
66

77
One of the cool things about CodeCommit is the support for IAM authentication. And if you are running this workshop from a Cloud9 workspace, you can leverage the fact that your terminal is already pre-authenticated with valid AWS credentials.
88

9-
Configure the git client with username and email, so your commits have an author defined.
9+
You can validate the Cloud9 git configuration with the following command:
1010

1111
```
12-
git config --global user.name "Replace with your name"
13-
git config --global user.email "replace_with_your_email@example.com"
12+
git config --get-regexp credential\.*
13+
```
14+
15+
You should see the following
16+
1417
```
18+
credential.helper !aws codecommit credential-helper $@
19+
credential.usehttppath true
20+
```
21+
22+
If you are running this workshop outside Cloud9 or do **not** see the same credential configuation
23+
above, refer to the [CodeCommit
24+
Authentication](https://docs.aws.amazon.com/codecommit/latest/userguide/auth-and-access-control.html)
25+
documentation.
1526

16-
Example:
27+
Configure the git client with username and email, so your commits have an author defined.
1728

18-
![CredsHelper](/images/java/chapter4/credhelper/cred-helper.png)
29+
```text
30+
git config --global user.name "Replace with your name"
31+
git config --global user.email "replace_with_your_email@example.com"
32+
```
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
+++
2+
title = "Inspect pipeline"
3+
date = 2019-11-05T14:20:52-08:00
4+
weight = 35
5+
+++
6+
7+
### Inspect the pipeline
8+
9+
Once the `sam-app-pipeline` CloudFormation stack has completed, you will have a new CodePipeline Pipeline.
10+
Navigate to the [CodePipeline Console](https://console.aws.amazon.com/codesuite/codepipeline/pipelines).
11+
You should see a single Pipeline. If you've navigated here soon after deploying the pipeline
12+
CloudFormation stack, you will see your new Pipeline exeuting its first deployment.
13+
14+
![Pipeline in-progress](/images/chapter4-pipelines/sam-app-pipeline-in-progress.png)
15+
16+
Let your pipeline run every stage. After it finishes all stages will be green.
17+
18+
![Pipline stages in-progress](/images/chapter4-pipelines/sam-app-pipeline-2.png)
19+
20+
{{% notice note %}}
21+
You may have noticed our `sam-app-dev` is deployed in a CodePipleine stage named `DeployTest`. The
22+
`DeployTest` name is hardcoded in the `codepipeline.yaml` file and does not relate in any way to our
23+
dev application that we named `sam-app-dev`. When you use this template outside this workshow you could
24+
rename `DeployTest` to anything appropriate.
25+
{{% /notice %}}
26+
27+
### Inspect the dev/prod stages
28+
29+
Nagivate to the CloudFormation console. After your first Pipeline has finished you will notice two
30+
new stacks named `sam-app-dev` and `sam-app-prod`. These are the names you provided during the SAM
31+
Pipelines wizard in the previous step.
32+
33+
CodeBuild created the `sam-app-dev` stack during the `DeployTest` Pipeline step. Similarly,
34+
CodeBuild created `sam-app-prod` during the `DeployProd` step.
35+
36+
Look at the `Outputs` tab for each of these CloudFormation stacks to see the API endpoints. You can
37+
use `curl` or other methods to verify the functionality of your two new APIs.
38+
39+
![API endpoints](/images/chapter4-pipelines/sam-app-dev-cfn-outputs.png)
40+
41+
#### You may have noticed that unit tests are not being run in your pipeline. Let's fix that in the next section!

0 commit comments

Comments
 (0)