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

Commit 8f724d6

Browse files
committed
Added all content
1 parent 4e918d7 commit 8f724d6

File tree

44 files changed

+1332
-0
lines changed

Some content is hidden

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

44 files changed

+1332
-0
lines changed

workshop/buildspec.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
version: 0.2
2+
phases:
3+
install:
4+
runtime-versions:
5+
golang: 1.12
6+
nodejs: 10
7+
commands:
8+
- echo Entered the install phase...
9+
- apt-get -qq update && apt-get -qq install curl
10+
- apt-get -qq install asciidoctor
11+
- curl -s -L https://github.com/gohugoio/hugo/releases/download/v0.55.6/hugo_0.55.6_Linux-64bit.deb -o hugo.deb
12+
- dpkg -i hugo.deb
13+
finally:
14+
- echo Installation done
15+
build:
16+
commands:
17+
- echo Entered the build phase ...
18+
- echo Build started on `date`
19+
- cd $CODEBUILD_SRC_DIR/workshop/themes
20+
- git clone https://github.com/matcornic/hugo-theme-learn.git learn
21+
- cd ../
22+
- hugo --quiet
23+
finally:
24+
- echo Building the HTML files finished
25+
artifacts:
26+
files:
27+
- "**/*"
28+
base-directory: $CODEBUILD_SRC_DIR/workshop/public/
29+
discard-paths: no

workshop/config.toml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
RelativeURLs=true
2+
CanonifyURLs=true
3+
languageCode = "en-US"
4+
defaultContentLanguage = "en"
5+
6+
title = "CI/CD for Serverless Applications"
7+
theme = "learn"
8+
metaDataFormat = "yaml"
9+
defaultContentLanguageInSubdir= true
10+
11+
uglyurls = true
12+
sectionPagesMenu = "main"
13+
pygmentsCodeFences = true
14+
pygmentsStyle = "monokai"
15+
16+
[params]
17+
editURL = "https://github.com/aws-samples/serverless-workshops"
18+
description = "Building a CI/CD pipeline for Serverless applications"
19+
author = "Fernando Dingler <fdingler@amazon.com>"
20+
disableBreadcrumb = false
21+
disableNextPrev = false
22+
themeVariant = "aws"
23+
disableSearch = false
24+
disableAssetsBusting = true
25+
disableLanguageSwitchingButton = false
26+
disableShortcutsTitle = true
27+
disableInlineCopyToClipBoard = true
28+
29+
[outputs]
30+
home = [ "HTML", "RSS", "JSON"]
31+
32+
[blackfriday]
33+
plainIDAnchors = true
34+
hrefTargetBlank = true
35+
36+
[Languages]
37+
[Languages.en]
38+
title = ""
39+
weight = 1
40+
languageName = "English"

workshop/content/_index.en.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
+++
2+
title = "CI/CD for Serverless Applications"
3+
chapter = true
4+
weight = 1
5+
+++
6+
# CI/CD for Serverless Applications
7+
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 AWS CodeCommit, AWS CodeBuild and AWS CodePipeline. You will also learn how to test a Serverless application locally using the SAM CLI.
9+
10+
![Intro](/images/intro.png)
11+
12+
{{% button href="mailto:fdingler@amazon.com" icon="fas fa-bug" %}}Report an issue{{% /button %}}
13+
{{% button href="mailto:aws-sa-customer-engagements@amazon.com" icon="fas fa-envelope" %}}Contact Event Outfitters{{% /button %}}
14+
{{% button href="https://aws.amazon.com/serverless/developer-tools" icon="fas fa-graduation-cap" %}}Learn more{{% /button %}}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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 automate the build, package and deploy commands by creating a continous delivery pipeline that, a high level, looks like the diagram below.
12+
13+
![SimplePipeline](/images/pipeline-art.png)
14+
15+
The services used in this chapter are AWS CodeCommit, AWS CodeBuild, AWS CodePipeline, AWS CloudFormation and the AWS Serverless Application Repository.
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
+++
2+
title = "Write the buildspec file"
3+
date = 2019-10-04T12:54:48-07:00
4+
weight = 30
5+
+++
6+
7+
A buildspec file is a series of commands in YAML format that CodeBuild runs to build your application.
8+
9+
Create a new file named _buildspec.yml_ in the root of the _sam-app_ directory and copy the following contents into it. **It is very important that the file is placed in the root**, otherwise CodeBuild will not be able to find it.
10+
11+
In Cloud9, right click on the `sam-app` directory to create a new file. Name it `buildspec.yml`.
12+
13+
![CreateNewFileCloud9](/images/screenshot-cloud9-new-file.png)
14+
15+
Then, paste the following content into the file:
16+
17+
```
18+
# ~/environment/sam-app/buildspec.yml
19+
20+
version: 0.2
21+
phases:
22+
install:
23+
runtime-versions:
24+
nodejs: 10
25+
commands:
26+
# Install packages or any pre-reqs in this phase.
27+
- cd hello-world
28+
- npm install
29+
30+
pre_build:
31+
commands:
32+
# Run tests, lint scripts or any other pre-build checks.
33+
- npm run test
34+
35+
build:
36+
commands:
37+
# Use Build phase to build your artifacts (compile, etc.)
38+
- cd ..
39+
- sam build
40+
41+
post_build:
42+
commands:
43+
# Use Post-Build for notifications, git tags, upload artifacts to S3
44+
- sam package --template-file template.yaml --s3-bucket $PACKAGE_BUCKET --output-template-file packaged.yaml
45+
46+
artifacts:
47+
discard-paths: yes
48+
files:
49+
# List of local artifacts that will be passed down the pipeline
50+
- packaged.yaml
51+
```
52+
53+
**Save the file**. It should look like this (take a moment to understand it):
54+
55+
![CreateBuildspec](/images/screenshot-buildspec.png)
56+
57+
### Push code changes
58+
Commit your changes and push them to the repository.
59+
60+
```
61+
git add .
62+
git commit -m "Added buildspec.yml"
63+
git push
64+
```
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
+++
2+
title = "Configure credentials"
3+
date = 2019-10-03T16:26:02-07:00
4+
weight = 10
5+
+++
6+
7+
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.
8+
9+
Run the following commands from your terminal:
10+
11+
```
12+
git config --global credential.helper '!aws codecommit credential-helper $@'
13+
git config --global credential.UseHttpPath true
14+
```
15+
16+
Now configure the git client with username and email, so your commits have an author defined.
17+
18+
```
19+
git config --global user.name "Replace with your name"
20+
git config --global user.email "replace_with_your_email@example.com"
21+
```
22+
23+
Example:
24+
25+
![CredsHelper](/images/screenshot-creds-helper.png)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
+++
2+
title = "Verify pipeline running"
3+
date = 2019-11-05T14:20:52-08:00
4+
weight = 35
5+
+++
6+
7+
Once you push the buildspec.yaml file into the code repository, the pipeline should trigger automatically. This time, the build step should succeed along with the deployment steps.
8+
9+
![VerifyPipelineRunning](/images/screenshot-pipeline-verify-3.png)
10+
11+
{{% notice tip %}}
12+
This pipeline performs deployments using CloudFormation ChangeSets. If you are not familiar with them, you can learn about them here: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-updating-stacks-changesets.html.
13+
{{% /notice %}}
14+
15+
#### Congratulations! You have created a CI/CD pipeline.
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
+++
2+
title = "Push the code"
3+
date = 2019-10-03T16:22:07-07:00
4+
weight = 15
5+
+++
6+
7+
### Ignore the build artifacts
8+
Copy and paste the following lines at the end of the `sam-app/.gitgnore` file. There is no need to track the .aws-sam directory or the packaged.yaml under version control as they are re-generated on every build.
9+
10+
```
11+
.aws-sam/
12+
packaged.yaml
13+
```
14+
15+
In Cloud9, remember to enable hidden files:
16+
17+
![EnableHiddenFiles](/images/screenshot-hidden-files-cloud9.png)
18+
19+
Open the `.gitignore` file and paste the two lines described above.
20+
21+
![GitIgnore](/images/screenshot-git-ignore.png)
22+
23+
From the root directory of your _sam-app_ project, run the following commands:
24+
25+
```
26+
cd ~/environment/sam-app
27+
git init
28+
git add .
29+
git commit -m "Initial commit"
30+
```
31+
32+
Example:
33+
![GitCommit](/images/screenshot-git-commit.png)
34+
35+
### Push the code
36+
Add your CodeCommit repository URL as a _remote_ on your local git project. This is the `cloneUrlHttp` value that you got back after creating the repository in Step 1 of this chapter.
37+
38+
{{% notice tip %}}
39+
If you can't find the CodeCommit repository URL, you can find it by running this command: `aws codecommit get-repository --repository-name sam-app`.
40+
{{% /notice %}}
41+
42+
```
43+
git remote add origin REPLACE_WITH_HTTP_CLONE_URL
44+
```
45+
46+
{{% notice tip %}}
47+
If you typed the origin url incorrectly, you can remove it by running: `git remote rm origin`.
48+
{{% /notice %}}
49+
50+
Now, push the code:
51+
52+
```
53+
git push -u origin master
54+
```
55+
56+
Example:
57+
58+
![GitPush](/images/screenshot-git-push.png)
59+
60+
### Verify in CodeCommit
61+
Navigate to the [AWS CodeCommit console](https://console.aws.amazon.com/codesuite/codecommit/home), find your _sam-app_ repository and click on it to view its contents. Make sure your code is there. You should see a screen like the following:
62+
63+
![VerifyCodeCommit](/images/screenshot-verify-codecommit.png)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
+++
2+
title = "Create a Git Repository"
3+
date = 2019-10-03T15:26:06-07:00
4+
weight = 5
5+
+++
6+
7+
Any CI/CD pipeline starts with a code repository. In this workshop we use AWS CodeCommit for ease of integration, but you could use other source code integrations, like GitHub for example.
8+
9+
Run the following command from your terminal to create a new CodeCommit repository:
10+
11+
```
12+
aws codecommit create-repository --repository-name sam-app
13+
```
14+
15+
You should see the following output. Copy the value of `cloneUrlHttp`, you will need it later.
16+
17+
![CreateCodeCommit](/images/screenshot-codecommit-create.png)

workshop/content/buildpipe/launch/_index.en.md

Whitespace-only changes.

0 commit comments

Comments
 (0)