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

Commit 048588f

Browse files
committed
updated READMEs for adding policies to LambdaExecutionRole
1 parent c0d0987 commit 048588f

File tree

5 files changed

+51
-62
lines changed

5 files changed

+51
-62
lines changed

DevOps/1_ServerlessApplicationModel/README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,7 @@ Below is a code snippet from the SAM template to list Unicorns:
3636
Properties:
3737
Path: /unicorns
3838
Method: get
39-
Role:
40-
Fn::ImportValue:
41-
!Join ['-', [!Ref 'ProjectId', !Ref 'AWS::Region', 'LambdaTrustRole']]
39+
Role: !GetAtt LambdaExecutionRole.Arn
4240
```
4341
4442
There are several [properties](https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#properties) defined for the [AWS::Serverless::Function](https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction) resource, which we'll review in turn.

DevOps/1_ServerlessApplicationModel/uni-api/template.yml

Lines changed: 1 addition & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -3,58 +3,6 @@ Transform:
33
- 'AWS::Serverless-2016-10-31'
44
- 'AWS::CodeStar'
55

6-
Description:
7-
Creates a RESTful API using API Gateway, Lambda and DynamoDB for the Wild Rydes serverless devops workshop
8-
9-
Parameters:
10-
ProjectId:
11-
Type: String
12-
Description: AWS CodeStar projectID used to associate new resources to team members
13-
CodeDeployRole:
14-
Type: String
15-
Description: IAM role to allow AWS CodeDeploy to manage deployment of AWS Lambda functions
16-
Stage:
17-
Type: String
18-
Description: The name for a project pipeline stage, such as Staging or Prod, for which resources are provisioned and deployed.
19-
Default: ''
20-
21-
Resources:
22-
ListFunction:
23-
Type: 'AWS::Serverless::Function'
24-
Properties:
25-
FunctionName: 'uni-api-list'
26-
Runtime: nodejs6.10
27-
CodeUri: app
28-
Handler: list.lambda_handler
29-
Description: List Unicorns
30-
Timeout: 10
31-
Events:
32-
GET:
33-
Type: Api
34-
Properties:
35-
Path: /unicorns
36-
Method: get
37-
Role: !GetAtt LambdaExecutionRole.Arn
38-
39-
LambdaExecutionRole:
40-
Description: Creating service role in IAM for AWS Lambda
41-
Type: AWS::IAM::Role
42-
Properties:
43-
RoleName: !Sub 'CodeStar-${ProjectId}-Execution${Stage}'
44-
AssumeRolePolicyDocument:
45-
Statement:
46-
- Effect: Allow
47-
Principal:
48-
Service: [lambda.amazonaws.com]
49-
Action: sts:AssumeRole
50-
Path: /
51-
ManagedPolicyArns:
52-
- arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
53-
PermissionsBoundary: !Sub 'arn:${AWS::Partition}:iam::${AWS::AccountId}:policy/CodeStar_${ProjectId}_PermissionsBoundary'AWSTemplateFormatVersion: '2010-09-09'
54-
Transform:
55-
- 'AWS::Serverless-2016-10-31'
56-
- 'AWS::CodeStar'
57-
586
Description:
597
Creates a RESTful API using API Gateway, Lambda and DynamoDB for the Wild Rydes serverless devops workshop
608

@@ -102,4 +50,4 @@ Resources:
10250
Path: /
10351
ManagedPolicyArns:
10452
- arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
105-
PermissionsBoundary: !Sub 'arn:${AWS::Partition}:iam::${AWS::AccountId}:policy/CodeStar_${ProjectId}_PermissionsBoundary'
53+
PermissionsBoundary: !Sub 'arn:${AWS::Partition}:iam::${AWS::AccountId}:policy/CodeStar_${ProjectId}_PermissionsBoundary'

DevOps/2_ContinuousDeliveryPipeline/README.md

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,18 +139,59 @@ Using a text editor, open the `template.yml` file and append a new **AWS::Server
139139
Environment:
140140
Variables:
141141
TABLE_NAME: !Ref Table
142-
Role:
143-
Fn::ImportValue:
144-
!Join ['-', [!Ref 'ProjectId', !Ref 'AWS::Region', 'LambdaTrustRole']]
142+
Role: !GetAtt LambdaExecutionRole.Arn
145143
```
146144
</details>
147145

148146
</details>
149147
<p>
150148

149+
Now that the API is using a DynamoDB table, we need to add permission for the Lambda Function to access it.
150+
151+
### 2. Update LambdaExecutionRole with DynamoDB access
152+
153+
**Goal**: Update the `AWS::IAM::Role` resource named **LambdaExecutionRole** in the `template.yml` SAM template to include the `arn:aws:iam::aws:policy/AmazonDynamoDBFullAccess` policy in the `ManagedPolicyArns` section.
154+
155+
<details>
156+
<summary><strong>
157+
HOW TO update the LambdaExecutionRole IAM Role in the template.yml with AmazonDynamoDBFullAccess (expand for details)
158+
</strong></summary>
159+
<p>
160+
161+
1. Using a text editor, open the `template.yml` file and find the **AWS::IAM:Role** Resource labeled `LambdaExecutionRole`.
162+
163+
2. Add `arn:aws:iam::aws:policy/AmazonDynamoDBFullAccess` to the list of ManagedPolicyArns.
164+
165+
If you are unsure of the syntax to add to ``template.yml`` please refer to the code snippet below.
166+
167+
<details>
168+
<summary><strong>template.yml changes for DynamoDB access (expand for details)</strong></summary><p>
169+
170+
```yaml
171+
LambdaExecutionRole:
172+
Description: Creating service role in IAM for AWS Lambda
173+
Type: AWS::IAM::Role
174+
Properties:
175+
RoleName: !Sub 'CodeStar-${ProjectId}-Execution${Stage}'
176+
AssumeRolePolicyDocument:
177+
Statement:
178+
- Effect: Allow
179+
Principal:
180+
Service: [lambda.amazonaws.com]
181+
Action: sts:AssumeRole
182+
Path: /
183+
ManagedPolicyArns:
184+
- arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
185+
- arn:aws:iam::aws:policy/AmazonDynamoDBFullAccess
186+
PermissionsBoundary: !Sub 'arn:${AWS::Partition}:iam::${AWS::AccountId}:policy/CodeStar_${ProjectId}_PermissionsBoundary'
187+
```
188+
</details>
189+
</details>
190+
<p>
191+
151192
Now that you've updated the the SAM template with the changes, use Git to commit the changes and push them to remote repository. This will trigger CodePipeline to build and deploy your changes in AWS.
152193

153-
### 2. Commit the change to local Git repository
194+
### 3. Commit the change to local Git repository
154195

155196
1. Using your Git client, add the local changes to the Git index, and commit with a message. For example:
156197

@@ -165,7 +206,7 @@ Now that you've updated the the SAM template with the changes, use Git to commit
165206
git push origin
166207
```
167208

168-
### 3. Confirm CodePipeline Completion
209+
### 4. Confirm CodePipeline Completion
169210

170211
**Goal**: After pushing your changes to your CodeCommit Git repository, use the AWS CodeStar Console to monitor and confirm that the changes are successfully built and deployed using CodePipeline.
171212

DevOps/3_XRay/uni-api/template.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,5 +124,5 @@ Resources:
124124
Path: /
125125
ManagedPolicyArns:
126126
- arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
127-
- arn:aws:iam::aws:policy/AWSXRayDaemonWriteAccess
127+
- arn:aws:iam::aws:policy/AmazonDynamoDBFullAccess
128128
PermissionsBoundary: !Sub 'arn:${AWS::Partition}:iam::${AWS::AccountId}:policy/CodeStar_${ProjectId}_PermissionsBoundary'

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,4 +124,6 @@ Resources:
124124
Path: /
125125
ManagedPolicyArns:
126126
- arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
127+
- arn:aws:iam::aws:policy/AmazonDynamoDBFullAccess
128+
- arn:aws:iam::aws:policy/AWSXRayDaemonWriteAccess
127129
PermissionsBoundary: !Sub 'arn:${AWS::Partition}:iam::${AWS::AccountId}:policy/CodeStar_${ProjectId}_PermissionsBoundary'

0 commit comments

Comments
 (0)