Skip to content

Commit 10feadc

Browse files
imphasingbrettstack
authored andcommitted
docs: document role parameter for DeploymentPreference (#642)
1 parent cbd4d9a commit 10feadc

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

docs/internals/generated_resources.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ Example:
7070
AutoPublishAlias: live
7171
DeploymentPreference:
7272
Type: Linear10PercentEvery10Minutes
73+
Role: "arn"
7374
...
7475
7576
@@ -83,6 +84,8 @@ AWS::CodeDeploy::DeploymentGroup MyFunction\ **DeploymentGroup**
8384
AWS::IAM::Role CodeDeployServiceRole
8485
================================== ================================
8586

87+
NOTE: ``AWS::IAM::Role`` resources are only generated if no Role parameter is supplied for DeploymentPreference
88+
8689
With Events
8790
~~~~~~~~~~~
8891

docs/safe_lambda_deployments.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ resource:
105105
# Validation Lambda functions that are run before & after traffic shifting
106106
PreTraffic: !Ref PreTrafficLambdaFunction
107107
PostTraffic: !Ref PostTrafficLambdaFunction
108+
# Provide a custom role for CodeDeploy traffic shifting here, if you don't supply one
109+
# SAM will create one for you with default permissions
110+
Role: !Ref IAMRoleForCodeDeploy # Parameter example, you can pass an IAM ARN
108111
109112
AliasErrorMetricGreaterThanZeroAlarm:
110113
Type: "AWS::CloudWatch::Alarm"
@@ -162,6 +165,7 @@ resource:
162165
FunctionName: 'CodeDeployHook_preTrafficHook'
163166
DeploymentPreference:
164167
Enabled: false
168+
Role: ""
165169
Environment:
166170
Variables:
167171
CurrentVersion: !Ref MyLambdaFunction.Version
@@ -176,6 +180,7 @@ CloudFormation, the following happens:
176180
- During traffic shifting, if any of the CloudWatch Alarms go to *Alarm* state, CodeDeploy will immediately flip the Alias back to old version and report a failure to CloudFormation.
177181
- After traffic shifting completes, CodeDeploy will invoke the **PostTraffic Hook** Lambda function. This is similar to PreTraffic Hook where the function must callback to CodeDeploy to report a Success or a Failure. PostTraffic hook is a great place to run integration tests or other validation actions.
178182
- If everything went well, the Alias will be pointing to the new Lambda Version.
183+
- If you supply the "Role" argument to the DeploymentPreference, it will prevent SAM from creating a role and instead use the provided CodeDeploy role for traffic shifting
179184

180185
NOTE: Verify that your AWS SDK version supports PutLifecycleEventHookExecutionStatus. For example, Python requires SDK version 1.4.8 or newer.
181186

@@ -294,7 +299,7 @@ Internally, SAM will create the following resources in your CloudFormation stack
294299
SAM template belongs to its own Deployment Group.
295300
- Adds ``UpdatePolicy`` on ``AWS::Lambda::Alias`` resource that is
296301
connected to the function's Deployment Group resource.
297-
- One ``AWS::IAM::Role`` called "CodeDeployServiceRole".
302+
- One ``AWS::IAM::Role`` called "CodeDeployServiceRole", if no custom role is provided
298303

299304
CodeDeploy assumes that there are no dependencies between Deployment Groups and hence will deploy them in parallel.
300305
Since every Lambda function is to its own CodeDeploy DeploymentGroup, they will be deployed in parallel.

samtranslator/model/preferences/deployment_preference.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
version.
1818
:param alarms: A list of Cloudwatch Alarm references that if ever in the alarm state during a deployment (or
1919
before a deployment starts) cause the deployment to fail and rollback.
20+
:param role: An IAM role ARN that CodeDeploy will use for traffic shifting, an IAM role will not be created if
21+
this is supplied
2022
:param enabled: Whether this deployment preference is enabled (true by default)
2123
"""
2224
DeploymentPreferenceTuple = namedtuple('DeploymentPreferenceTuple',

0 commit comments

Comments
 (0)