You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Nov 4, 2022. It is now read-only.
@@ -33,7 +38,30 @@ After a few seconds, our new CDK project should look like this:
33
38
34
39
35
40
### 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**.
Copy file name to clipboardExpand all lines: workshop/content/buildpipe/howto/_index.en.md
+5-3Lines changed: 5 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,16 +7,18 @@ weight = 20
7
7
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.
8
8
9
9
### 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:
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.
19
19
20
20
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.
21
21
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.
Copy file name to clipboardExpand all lines: workshop/content/buildpipe/pipeascode/_index.en.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@ date = 2019-11-01T15:26:09-07:00
4
4
weight = 22
5
5
+++
6
6
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.
Copy file name to clipboardExpand all lines: workshop/content/buildpipe/pipeascode/bucket/_index.en.md
+6Lines changed: 6 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,6 +8,8 @@ Every Code Pipeline needs an artifacts bucket, also known as Artifact Store. Cod
8
8
9
9
Let's get started and write the code for creating this bucket:
10
10
11
+
**Make sure you are editing the file with _.ts_ extension**
12
+
11
13
```js
12
14
// lib/pipeline-stack.ts
13
15
@@ -31,6 +33,10 @@ npm run build
31
33
cdk deploy
32
34
```
33
35
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
+
34
40
The output will show that the S3 bucket got created:
Copy file name to clipboardExpand all lines: workshop/content/buildpipe/pipeascode/build/_index.en.md
+6-2Lines changed: 6 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,10 +4,14 @@ date = 2019-11-01T15:26:09-07:00
4
4
weight = 20
5
5
+++
6
6
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?
8
10
9
11
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.
10
12
13
+
### Add the build stage
14
+
11
15
Let's go ahead and add a Build stage to our pipeline:
12
16
13
17
```js
@@ -99,7 +103,7 @@ Navigate to the [AWS CodePipeline Console](https://console.aws.amazon.com/codesu
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.
Copy file name to clipboardExpand all lines: workshop/content/buildpipe/pipeascode/buildspec/_index.en.md
+3-1Lines changed: 3 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@ date = 2019-10-04T12:54:48-07:00
4
4
weight = 30
5
5
+++
6
6
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.
8
8
9
9
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.
10
10
@@ -63,9 +63,11 @@ artifacts:
63
63
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.
64
64
65
65
### Push code changes
66
+
66
67
Commit your changes and push them to the repository.
Copy file name to clipboardExpand all lines: workshop/content/buildpipe/pipeascode/deploy/_index.en.md
+3-2Lines changed: 3 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@ date = 2019-10-04T12:54:48-07:00
4
4
weight = 40
5
5
+++
6
6
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_.
8
8
9
9
Add the Deploy stage to your pipeline:
10
10
@@ -108,11 +108,12 @@ export class PipelineStack extends cdk.Stack {
108
108
On your terminal, run the following commands from within the _pipeline_ directory:
109
109
110
110
```
111
+
cd ~/environment/sam-app/pipeline
111
112
npm run build
112
113
cdk deploy
113
114
```
114
115
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.
Copy file name to clipboardExpand all lines: workshop/content/buildpipe/pipeascode/source/_index.en.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@ date = 2019-11-01T15:26:09-07:00
4
4
weight = 15
5
5
+++
6
6
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.
8
8
9
9
Let's go ahead and add a Source provider to our pipeline:
Copy file name to clipboardExpand all lines: workshop/content/manualdeploy/_index.en.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,4 +11,4 @@ Before we start building a fully automated continous delivery pipeline, in this
11
11
12
12

13
13
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