Skip to content
This repository was archived by the owner on Jan 14, 2025. It is now read-only.

Commit 21ea513

Browse files
committed
Update README and templates to support multi-environment.
1 parent 623d5c1 commit 21ea513

File tree

4 files changed

+43
-113
lines changed

4 files changed

+43
-113
lines changed

DevOps/4_MultipleEnvironments/README.md

Lines changed: 36 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -71,81 +71,7 @@ Each of the following sections provide an implementation overview and detailed,
7171

7272
If you're using the latest version of the Chrome, Firefox, or Safari web browsers the step-by-step instructions won't be visible until you expand the section.
7373

74-
### 1. Update CodeStar IAM Roles
75-
76-
CodeStar generates IAM Roles and Policies that control access to AWS resources. In this module, we will add permissions to Roles using IAM Managed Policies to support the customizations we will make to the CodePipeline pipeline by adding additional deployment environments and serverless unit testing.
77-
78-
#### 1a. Update `CodeStarWorker-uni-api-Lambda`IAM Role
79-
80-
1. In the AWS Management Console choose **Services** then select **IAM** under Security, Identity & Compliance.
81-
82-
1. Select Role in the left navigation, type `CodeStarWorker-uni-api-Lambda` in the filter text box, and click the Role name link in the Role table.
83-
84-
![Select Role](images/role1-1.png)
85-
86-
1. On the Role Summary page, click the **Attach Policy** button in the **Managed Policies** section of the **Permissions** tab.
87-
88-
![Role Details](images/role1-2.png)
89-
90-
1. Type `AWSCodePipelineCustomActionAccess` in the filter text box, select the checkbox next to the **AWSCodePipelineCustomActionAccess** Managed Policy.
91-
92-
![Attach Policy](images/role1-3.png)
93-
94-
1. Type `AWSCloudFormationReadOnlyAccess` in the filter text box, select the checkbox next to the **AWSCloudFormationReadOnlyAccess** Managed Policy.
95-
96-
![Attach Policy](images/role1-4.png)
97-
98-
1. Type `AmazonDynamoDBFullAccess` in the filter text box, select the checkbox next to the **AmazonDynamoDBFullAccess** Managed Policy, and click the **Attach Policy** button.
99-
100-
![Attach Policy](images/role1-5.png)
101-
102-
1. Type `AWSLambdaRole` in the filter text box, select the checkbox next to the **AWSLambdaRole** Managed Policy, and click the **Attach Policy** button.
103-
104-
![Attach Policy](images/role1-6.png)
105-
106-
1. The Role Summary will now include the **AWSCodePipelineCustomActionAccess**, **AWSCloudFormationReadOnlyAccess**, and **AWSLambdaRole** policies in the list of **Managed Policies**.
107-
108-
![Policy Attached](images/role1-7.png)
109-
110-
#### 1b. Update `CodeStarWorker-uni-api-CodePipeline` IAM Role
111-
112-
1. In the AWS Management Console choose **Services** then select **IAM** under Security, Identity & Compliance.
113-
114-
1. Select Role in the left navigation, type `CodeStarWorker-uni-api-CodePipeline` in the filter text box, and click the Role name link in the Role table.
115-
116-
![Select Role](images/role2-1.png)
117-
118-
1. On the Role Summary page, click the **Attach Policy** button in the **Managed Policies** section of the **Permissions** tab.
119-
120-
![Role Details](images/role2-2.png)
121-
122-
1. Type `AWSCodePipelineReadOnlyAccess` in the filter text box, select the checkbox next to the **AWSCodePipelineReadOnlyAccess** Managed Policy.
123-
124-
![Attach Policy](images/role2-3.png)
125-
126-
1. Type `AWSLambdaRole` in the filter text box, select the checkbox next to the **AWSLambdaRole** Managed Policy and click the **Attach Policy** button.
127-
128-
![Attach Policy](images/role2-5.png)
129-
130-
1. The Role Summary will now include the **AWSCodePipelineReadOnlyAccess** and **AWSLambdaRole** policies in the list of **Managed Policies**.
131-
132-
![Policy Attached](images/role2-6.png)
133-
134-
#### 1c. Update `CodeStarWorkerCodePipelineRolePolicy` IAM Policy
135-
136-
1. Whilst still viewing the `CodeStarWorker-uni-api-CodePipeline` IAM Role, click **Edit Policy** for the `CodeStarWorkerCodePipelineRolePolicy` in the **Inline Policies** section.
137-
138-
![Policy Attached](images/role2-7.png)
139-
140-
1. Update the allowed CloudFormation Resource pattern in the policy (substitute your AWS Region and AccountId) a click **Save**.
141-
142-
Before: `arn:aws:cloudformation:{region}:{accountId}:stack/awscodestar-uni-api-lambda/*`
143-
144-
After: `arn:aws:cloudformation:{region}:{accountId}:stack/awscodestar-uni-api-lambda*`
145-
146-
![Policy Attached](images/role2-8.png)
147-
148-
### 2. Seed the `uni-api` CodeCommit Git repository
74+
### 1. Seed the `uni-api` CodeCommit Git repository
14975

15076
1. Each module has corresponding source code used to seed the CodeStar CodeCommit Git repository to support the workshop. To seed the CodeCommit Git repository, click on the **Launch Stack** button for your region below:
15177

@@ -171,7 +97,7 @@ CodeStar generates IAM Roles and Policies that control access to AWS resources.
17197

17298
![CloudFormation Stack Creation Complete](images/seed-repository-2.png)
17399

174-
### 3. Fetch CodeCommit Git Repository
100+
### 2. Fetch CodeCommit Git Repository
175101

176102
Now that the CodeCommit Git repository has been seeded with new source code, you will need to fetch the changes locally so that you may modify the code. Typically, this is accomplished using the `git pull` command, however for the workshop we have replaced the repository with a new history and different Git commands will be used.
177103

@@ -180,9 +106,9 @@ Using your preferred Git client, run the commands on your local **uni-api** Git
180106
* `git fetch --all`
181107
* `git reset --hard origin/master`
182108

183-
### 4. Add Test Stage
109+
### 3. Add Test Stage
184110

185-
#### 4a. Edit CodePipeline
111+
#### 3a. Edit CodePipeline
186112

187113
1. In the AWS Management Console choose **Services** then select **CodeStar** under Developer Tools.
188114

@@ -196,19 +122,19 @@ Using your preferred Git client, run the commands on your local **uni-api** Git
196122

197123
1. On the CodePipeline page, click **Edit**.
198124

199-
#### 4b. Add Test Stage
125+
#### 3b. Add Test Stage
200126

201127
1. Choose **+Stage** below the Build stage of the pipeline.
202128

203129
![CodePipeline Edit](images/codepipeline-edit-new.png)
204130

205131
1. Enter `Test` for the **Stage Name**.
206132

207-
#### 4c. Add GenerateChangeSet Action to Test Stage
133+
#### 3c. Add GenerateChangeSet Action to Test Stage
208134

209-
1. Choose `+Action` below `Test`.
135+
1. Choose `+ Add action group` below `Test`.
210136

211-
1. In the **Add action** dialog, enter `GenerateChangeSet` for the **Action name**.
137+
1. In the **Add action group** dialog, enter `GenerateChangeSet` for the **Action name**.
212138

213139
1. Select `AWS CloudFormation` for the **Action provider**.
214140

@@ -220,27 +146,27 @@ Using your preferred Git client, run the commands on your local **uni-api** Git
220146

221147
1. Enter `uni-api-BuildArtifact::test-template-export.yml` for **Template**
222148

223-
1. Select `CAPABILITY_IAM` for **Capabilities**
149+
1. Enter `uni-api-BuildArtifact::template-configuration.json` for **Template configuration**
150+
151+
1. Select `CAPABILITY_NAMED_IAM` for **Capabilities**
224152

225153
1. Enter `CodeStarWorker-uni-api-CloudFormation` for **Role name**
226154

227-
1. Expand the **Advanced** section and enter `{ "ProjectId": "uni-api" }` for Parameter overrides
155+
1. Expand the **Advanced** section and enter `{"ProjectId":"uni-api", "CodeDeployRole":"arn:aws:iam::YOUR_ACCOUNT_NUMBER:role/CodeStarWorker-uni-api-CodeDeploy"}` for Parameter overrides, substituting **YOUR_ACCOUNT_NUMBER** with your AWS account number.
228156

229157
1. Enter `uni-api-BuildArtifact` for **Input artifacts #1**
230158

231159
1. Choose **Save**
232160

233161
![CodePipeline Add Action](images/codepipeline-add-1-new.png)
234162

235-
#### 4d. Add ExecuteChangeSet Action to Test Stage
163+
#### 3d. Add ExecuteChangeSet Action to Test Stage
236164

237-
1. Choose `+Action` below `GenerateChangeSet`.
165+
1. Choose `+ Add action group` below `GenerateChangeSet`.
238166

239167
![CodePipeline Add Action](images/codepipeline-add2-1-new.png)
240168

241-
1. In the **Add action** dialog, select `AWS CloudFormation` for the **Action provider**.
242-
243-
1. Enter `ExecuteChangeSet` for the **Action name**.
169+
1. In the **Add action group** dialog, enter `ExecuteChangeSet` for the **Action name**.
244170

245171
1. Select `AWS CloudFormation` for the **Action provider**.
246172

@@ -254,15 +180,17 @@ Using your preferred Git client, run the commands on your local **uni-api** Git
254180

255181
1. Choose **Save**
256182

257-
#### 4e. Save CodePipeline Changes
183+
1. Choose **Done** in the top right of the Stage.
184+
185+
#### 3e. Save CodePipeline Changes
258186

259187
The pipeline should look like the following screenshot after adding the new Test stage.
260188

261189
![CodePipeline Deploy Stage Complete](images/codepipeline-add2-complete-new.png)
262190

263-
1. Scroll to the top of the pipeline and choose `Save pipeline changes`
191+
1. Scroll to the top of the pipeline and choose `Save`
264192

265-
1. Choose `Save and Continue` when prompted by the Save Pipeline Changes dialog.
193+
1. Choose `Save` when prompted by the Save Pipeline Changes dialog.
266194

267195
## Test Stage Validation
268196

@@ -312,11 +240,9 @@ The addition of the Test stage is complete. You will now validate the Test stag
312240

313241
#### 1c. Add GenerateChangeSet to Beta Stage
314242

315-
1. Choose `+Action` below `Beta`.
316-
317-
1. In the **Add action** dialog, select `AWS CloudFormation` for the **Action provider**.
243+
1. Choose `+ Add action group` below `Beta`.
318244

319-
1. Enter `GenerateChangeSet` for the **Action name**.
245+
1. In the **Add action** dialog, enter `GenerateChangeSet` for the **Action name**.
320246

321247
1. Select `AWS CloudFormation` for the **Action provider**.
322248

@@ -328,27 +254,27 @@ The addition of the Test stage is complete. You will now validate the Test stag
328254

329255
1. Enter `uni-api-BuildArtifact::template-export.yml` for **Template**
330256

331-
1. Select `CAPABILITY_IAM` for **Capabilities**
257+
1. Enter `uni-api-BuildArtifact::template-configuration.json` for **Template configuration**
258+
259+
1. Select `CAPABILITY_NAMED_IAM` for **Capabilities**
332260

333261
1. Enter `CodeStarWorker-uni-api-CloudFormation` for **Role name**
334262

335-
1. Expand the **Advanced** section and enter `{ "ProjectId": "uni-api", "CustomSuffix": "-beta" }` for **Parameter overrides**
263+
1. Expand the **Advanced** section and enter `{"ProjectId":"uni-api", "CodeDeployRole":"arn:aws:iam::YOUR_ACCOUNT_NUMBER:role/CodeStarWorker-uni-api-CodeDeploy", "CustomSuffix": "-beta" }` for **Parameter overrides**
336264

337265
1. Enter `uni-api-BuildArtifact` for **Input artifacts #1**
338266

339-
1. Choose **Add**
267+
1. Choose **Save**
340268

341269
![CodePipeline Add Action Artifacts](images/codepipeline-add-3-new.png)
342270

343271
#### 1d. Add ExecuteChangeSet to Beta Stage
344272

345-
1. Choose `+Action` below `GenerateChangeSet`.
273+
1. Choose `+ Add action group` below `GenerateChangeSet`.
346274

347275
![CodePipeline Add Action](images/codepipeline-add4-1-new.png)
348276

349-
1. In the **Add action** dialog, select `AWS CloudFormation` for the **Action provider**.
350-
351-
1. Enter `ExecuteChangeSet` for the **Action name**.
277+
1. In the **Add action** dialog, enter `ExecuteChangeSet` for the **Action name**.
352278

353279
1. Select `AWS CloudFormation` for the **Action provider**.
354280

@@ -364,22 +290,22 @@ The addition of the Test stage is complete. You will now validate the Test stag
364290

365291
#### 1e. Add Invoke to Beta Stage
366292

367-
1. Choose `+Action` below `ExecuteChangeSet`.
293+
1. Choose `+ Add action group` below `ExecuteChangeSet`.
368294

369295
![CodePipeline Add Action](images/codepipeline-add4-2-new.png)
370296

371-
1. In the **Add action** dialog, select `Invoke` for the **Action category**.
372-
373-
1. Enter `InvokeLambdaTestFunction` for the **Action name**.
297+
1. In the **Add action** dialog, enter `InvokeLambdaTestFunction` for the **Action name**.
374298

375299
1. Select `AWS Lambda` for the **Action provider**.
376300

377301
1. Enter `uni-api-test-setup` for **Function name**.
378302

379303
1. Enter `awscodestar-uni-api-lambda-beta` for **User parameters**.
380304

381-
1. Choose **Add Action**
305+
1. Choose **Save**
382306

307+
1. Choose **Done** in the upper right corner of the Stage.
308+
383309
![CodePipeline Add Action](images/codepipeline-add4-4-new.png)
384310

385311
#### 1f. Save CodePipeline Changes
@@ -388,9 +314,9 @@ The pipeline should look like the following screenshot after adding the new Test
388314

389315
![CodePipeline Deploy Stage Complete](images/codepipeline-add3-complete-new.png)
390316

391-
1. Scroll to the top of the pipeline and choose `Save pipeline changes`
317+
1. Scroll to the top of the pipeline and choose `Save`
392318

393-
1. Choose `Save and Continue` when prompted by the Save Pipeline Changes dialog.
319+
1. Choose `Save` when prompted by the Save Pipeline Changes dialog.
394320

395321
## Beta Stage Validation
396322

DevOps/4_MultipleEnvironments/uni-api/buildspec.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ phases:
2020
commands:
2121
# Use AWS SAM to package the application using AWS CloudFormation
2222
- aws cloudformation package --template template.yml --s3-bucket $S3_BUCKET --output-template template-export.yml
23+
- aws cloudformation package --template test-template.yml --s3-bucket $S3_BUCKET --output-template test-template-export.yml
2324

2425
# Do not remove this statement. This command is required for AWS CodeStar projects.
2526
# Update the AWS Partition, AWS Region, account ID and project ID in the project ARN on template-configuration.json file so AWS CloudFormation can tag project resources.
@@ -29,4 +30,5 @@ artifacts:
2930
type: zip
3031
files:
3132
- template-export.yml
33+
- test-template-export.yml
3234
- template-configuration.json

DevOps/4_MultipleEnvironments/uni-api/template.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ Resources:
114114
Description: Creating service role in IAM for AWS Lambda
115115
Type: AWS::IAM::Role
116116
Properties:
117-
RoleName: !Sub 'CodeStar-${ProjectId}-Execution${Stage}'
117+
RoleName: !Sub 'CodeStar-${ProjectId}-Execution${Stage}${CustomSuffix}'
118118
AssumeRolePolicyDocument:
119119
Statement:
120120
- Effect: Allow

DevOps/4_MultipleEnvironments/uni-api/test-template.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ Resources:
4747
Description: Creating service role in IAM for AWS Lambda
4848
Type: AWS::IAM::Role
4949
Properties:
50-
RoleName: !Sub 'CodeStar-${ProjectId}-Execution${Stage}'
50+
RoleName: !Sub 'CodeStar-${ProjectId}-Execution${Stage}-Test'
5151
AssumeRolePolicyDocument:
5252
Statement:
5353
- Effect: Allow
@@ -57,5 +57,7 @@ Resources:
5757
Path: /
5858
ManagedPolicyArns:
5959
- arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
60-
- arn:aws:iam::aws:policy/AWSXRayDaemonWriteAccess
60+
- arn:aws:iam::aws:policy/service-role/AWSLambdaRole
61+
- arn:aws:iam::aws:policy/AWSCodePipelineCustomActionAccess
62+
- arn:aws:iam::aws:policy/AWSCloudFormationReadOnlyAccess
6163
PermissionsBoundary: !Sub 'arn:${AWS::Partition}:iam::${AWS::AccountId}:policy/CodeStar_${ProjectId}_PermissionsBoundary'

0 commit comments

Comments
 (0)