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

Commit ba32aae

Browse files
committed
Minor fixes to CDK instructions
1 parent bfdccf2 commit ba32aae

File tree

13 files changed

+143
-17
lines changed

13 files changed

+143
-17
lines changed

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

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,15 @@ mkdir pipeline
1818
cd pipeline
1919
```
2020

21-
Initialize a new CDK project within the _pipeline_ folder by running the following commands:
21+
Initialize a new CDK project within the _pipeline_ folder by running the following command:
2222

2323
```
2424
cdk init --language typescript
25+
```
26+
27+
Now install the CDK modules that we will be using to build a pipeline:
28+
29+
```
2530
npm install --save @aws-cdk/aws-codedeploy @aws-cdk/aws-codebuild
2631
npm install --save @aws-cdk/aws-codecommit @aws-cdk/aws-codepipeline-actions
2732
npm install --save @aws-cdk/aws-s3
@@ -33,7 +38,30 @@ After a few seconds, our new CDK project should look like this:
3338

3439

3540
### Project structure
36-
The main files that you will be interacting with are _lib/pipeline-stack.ts_ and _bin/pipeline.ts_. Don't worry about the rest of the files and folders for now. Open the `bin/pipeline.ts` file, which is your entry point to the CDK project, and change the name of the stack to `sam-app-cicd`:
41+
42+
At this point, your project should have the structure below (only the most relevant files and folders are shown). Within the CDK project, the main file you will be interacting with is the _pipeline-stack.ts_. Don't worry about the rest of the files for now.
43+
44+
```
45+
sam-app # SAM application root
46+
├── hello-world # Lambda code
47+
├── samconfig.toml # Config file for manual deployments
48+
├── template.yaml # SAM template
49+
└── pipeline # CDK project root
50+
└── lib
51+
└── pipeline-stack.ts # Pipeline definition
52+
└── bin
53+
└── pipeline.ts # Entry point for CDK project
54+
├── cdk.json
55+
├── tsconfig.json
56+
├── package.json
57+
└── jest.config.js
58+
```
59+
60+
### Modify stack name
61+
62+
Open the `bin/pipeline.ts` file, which is your entry point to the CDK project, and change the name of the stack to **sam-app-cicd**.
3763

3864
![CdkEntryPoint](/images/chapter4/screenshot-bin-pipeline-ts.png)
3965

66+
**Save the file**.
67+

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ date = 2019-11-05T14:20:52-08:00
44
weight = 35
55
+++
66

7-
Once your pipeline has finished every stage successfully, it should look like the following screenshot:
7+
Let your pipline run every stage. After it finishes it will look all green like the following screenshot:
88

99
![VerifyPipelineRunning](/images/chapter4/screenshot-pipeline-verify-3.png)
1010

workshop/content/buildpipe/pipeline/_index.en.md renamed to workshop/content/buildpipe/howto/_index.en.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,18 @@ weight = 20
77
The best way to automate the creation of CI/CD pipelines is by provisioning them programmatically via Infrastructure as Code. This is specially useful in a microservices environment, where you have a pipeline per microservice, which potentially means dozens of pipelines, if not more. Having an automated way to create these pipelines enables developers to create as many as necessary without building them manually from the console every time.
88

99
### Different ways to create pipelines
10-
We see customers using different mechanisms for creating pipelines programmatically. The reality is that developers have many choices available, but the most common ones we see are the following:
10+
We see customers using different mechanisms for creating pipelines programmatically. Nowadays developers have many choices to pick from, but the most common ones we see are the following:
1111

1212
- [AWS CloudFormation](https://docs.aws.amazon.com/codepipeline/latest/userguide/tutorials.html)
1313
- [AWS CDK](https://docs.aws.amazon.com/cdk/latest/guide/codepipeline_example.html)
1414
- [Terraform](https://www.terraform.io/docs/providers/aws/r/codepipeline.html)
1515
- [AWS Serverless App Repository](https://serverlessrepo.aws.amazon.com/applications/arn:aws:serverlessrepo:us-east-1:646794253159:applications~aws-sam-codepipeline-cd)
1616

1717
### Introducing the AWS CDK
18-
In this workshop, we are going to use the AWS Cloud Development Kit (CDK) as the pipeline vending mechanism. The AWS CDK is a software development framework for defining cloud infrastructure in code and provisioning it through AWS CloudFormation.
18+
In this workshop, we are going to use the AWS Cloud Development Kit (also known as CDK), as the pipeline vending mechanism. The AWS CDK is a software development framework for defining cloud infrastructure in code and provisioning it through AWS CloudFormation.
1919

2020
That's right! You can describe your infrastructure by writing code in TypeScript, C#, Python or Java. Your code is then synthesized into CloudFormation and using the CDK CLI you can deploy it to an AWS account.
2121

22-
Continue on the next page to learn how to initialize a CDK project.
22+
### How does SAM and CDK play together?
23+
24+
Serverless developers use the SAM framework to define their applications, SAM CLI to build them and deploy them and AWS CDK to provision any infrastructure related resources, like their CI/CD Pipeline. The nice thing about these tools is that they all share a common ground: CloudFormation.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ date = 2019-11-01T15:26:09-07:00
44
weight = 22
55
+++
66

7-
Open the file `lib/pipeline-stack.ts` in your Cloud9 workspace. It is empty at the moment, but you will be adding code to describe and build your CI/CD pipeline in the following pages.
7+
Open the file `lib/pipeline-stack.ts` in your Cloud9 workspace. It is empty at the moment, but here is where you will be adding code to build your CI/CD pipeline.
88

99
![CdkEmptyLib](/images/chapter4/screenshot-cdk-empty.png)
1010

workshop/content/buildpipe/pipeascode/bucket/_index.en.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ Every Code Pipeline needs an artifacts bucket, also known as Artifact Store. Cod
88

99
Let's get started and write the code for creating this bucket:
1010

11+
**Make sure you are editing the file with _.ts_ extension**
12+
1113
```js
1214
// lib/pipeline-stack.ts
1315

@@ -31,6 +33,10 @@ npm run build
3133
cdk deploy
3234
```
3335

36+
{{% notice info %}}
37+
If you get a build error, check that all the @aws-cdk dependencies in the package.json file have the same version number, if not, fix it, delete the node_modules folder and run npm install. More info: https://github.com/aws/aws-cdk/issues/542#issuecomment-449694450.
38+
{{% /notice %}}
39+
3440
The output will show that the S3 bucket got created:
3541

3642
![CdkBucket](/images/chapter4/screenshot-cdk-s3-bucket.png)

workshop/content/buildpipe/pipeascode/build/_index.en.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,14 @@ date = 2019-11-01T15:26:09-07:00
44
weight = 20
55
+++
66

7-
The build stage is where your Serverless application gets built and packaged. We are going to use AWS CodeBuild as the Build provider for our pipeline. It is worth mentioning that CodePipeline also supports other providers like Jenkins, TeamCity or CloudBees.
7+
The **Build Stage** is where your Serverless application gets built and packaged by SAM. We are going to use AWS CodeBuild as the Build provider for our pipeline. It is worth mentioning that CodePipeline also supports other providers like Jenkins, TeamCity or CloudBees.
8+
9+
### Why AWS Code Build?
810

911
AWS CodeBuild is a great option because you only pay for the time where your build is running, which makes it very cost effective compared to running a dedicated build server 24 hours a day when you really only build during office hours. It is also container-based which means that you can bring your own Docker container image where your build runs, or [use a managed image](https://docs.aws.amazon.com/codebuild/latest/userguide/build-env-ref-available.html) provided by CodeBuild.
1012

13+
### Add the build stage
14+
1115
Let's go ahead and add a Build stage to our pipeline:
1216

1317
```js
@@ -99,7 +103,7 @@ Navigate to the [AWS CodePipeline Console](https://console.aws.amazon.com/codesu
99103

100104
![VerifyPipeline](/images/chapter4/screenshot-pipeline-verify-1.png)
101105

102-
Oh no! the Build step failed. **Don't worry, this is expected** because we haven't specified what commands to run on the build yet so AWS CodeBuild doesn't know how to build our Serverless application.
106+
The Build step should have failed. **Don't worry! this is expected** because we haven't specified what commands to run during the build yet, so AWS CodeBuild doesn't know how to build our Serverless application.
103107

104108
![VerifyPipeline](/images/chapter4/screenshot-pipeline-verify-2.png)
105109

workshop/content/buildpipe/pipeascode/buildspec/_index.en.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ date = 2019-10-04T12:54:48-07:00
44
weight = 30
55
+++
66

7-
A buildspec file is a series of commands in YAML format that CodeBuild executes to build your application. This file is placed in the root folder of a SAM application and CodeBuild will automatically find it and run it during build time.
7+
A **Buildspec File** is a series of commands in YAML format that CodeBuild executes to build your application. This file is placed in the root folder of a SAM application and CodeBuild will automatically find it and run it during build time.
88

99
In your Cloud9 editor, create a new file named `buildspec.yml` in the root (top level) of the _sam-app_ directory by right clicking on the `sam-app` folder and selecting New file.
1010

@@ -63,9 +63,11 @@ artifacts:
6363
Take a moment to understand the structure of the file and feel free to read the Buildsec Reference here: https://docs.aws.amazon.com/codebuild/latest/userguide/build-spec-ref.html.
6464

6565
### Push code changes
66+
6667
Commit your changes and push them to the repository.
6768

6869
```
70+
cd ~/environment/sam-app
6971
git add .
7072
git commit -m "Added buildspec.yml"
7173
git push

workshop/content/buildpipe/pipeascode/deploy/_index.en.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ date = 2019-10-04T12:54:48-07:00
44
weight = 40
55
+++
66

7-
The deploy stage is where your SAM application and all its resources are created an in an AWS account. The most common way to do this is by using CloudFormation ChangeSets to deploy. This means that this stage will have 2 actions: the _CreateChangeSet_ and the _ExecuteChangeSet_.
7+
The **Deploy Stage** is where your SAM application and all its resources are created an in an AWS account. The most common way to do this is by using CloudFormation ChangeSets to deploy. This means that this stage will have 2 actions: the _CreateChangeSet_ and the _ExecuteChangeSet_.
88

99
Add the Deploy stage to your pipeline:
1010

@@ -108,11 +108,12 @@ export class PipelineStack extends cdk.Stack {
108108
On your terminal, run the following commands from within the _pipeline_ directory:
109109

110110
```
111+
cd ~/environment/sam-app/pipeline
111112
npm run build
112113
cdk deploy
113114
```
114115

115-
The CDK CLI might ask you to confirm the changes before deploying, this is because we are giving Admin permissions to the IAM role that deploys our application. This is generally not a bad practice since this role can only be assumed by CloudFormation and not by a human, however, if your organization has a stricter security posture you may want to consider providing a fine grain policy for the deployment role.
116+
The CLI might ask you to confirm the changes before deploying, this is because we are giving Admin permissions to the IAM role that deploys our application. This is generally **not** a bad practice since this role can only be assumed by CloudFormation and not by a human, however, if your organization has a stricter security posture you may want to consider creating [a custom IAM deployment role](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-iam.Role.html) with a fine grain policy.
116117

117118
### Trigger a release
118119

workshop/content/buildpipe/pipeascode/source/_index.en.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ date = 2019-11-01T15:26:09-07:00
44
weight = 15
55
+++
66

7-
The source stage is the first step of any CI/CD pipeline and it represents your source code. This stage is in charge of triggering the pipeline based on new code changes (i.e. git push or pull requests). In this workshop, we will be using AWS CodeCommit as the source provider, but CodePipeline also supports S3, GitHub and Amazon ECR as source providers.
7+
The **Source Stage** is the first step of any CI/CD pipeline and it represents your source code. This stage is in charge of triggering the pipeline based on new code changes (i.e. git push or pull requests). In this workshop, we will be using AWS CodeCommit as the source provider, but CodePipeline also supports S3, GitHub and Amazon ECR as source providers.
88

99
Let's go ahead and add a Source provider to our pipeline:
1010

workshop/content/manualdeploy/_index.en.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ Before we start building a fully automated continous delivery pipeline, in this
1111

1212
![ManualDeploy](/images/manual-deploy-art.png)
1313

14-
Even though this workshop is about automating deployments, this chapter is very important to learn the foundation of how to package and deploy a Serverless application. You need to learn the basic commands that you will be automating with a pipeline in the next chapter.
14+
Even though this workshop is about automating deployments, this chapter is very important to learn the foundation of how to package and deploy a Serverless application. Learning how to perform manual deployments is also useful for developers who want to create their own personal stack and deploy it often to test changes before commiting them to the source control repository.

0 commit comments

Comments
 (0)