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
Copy file name to clipboardExpand all lines: DESIGN.md
+8Lines changed: 8 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,3 +1,11 @@
1
+
# Overview
2
+
3
+
SAM is called by the CloudFormation Service. CloudFormation recognises the `Transform: AWS::Serverless-2016-10-31` header and invokes the SAM translator. This will then take your SAM template and expand it
4
+
into a full fledged CloudFormation Template. The CloudFormation Template that is produced from SAM is the template that is executed by CloudFormation to create/update/delete AWS resources.
5
+
6
+
The entry point for SAM starts in the Translator class [here](https://github.com/awslabs/serverless-application-model/blob/develop/samtranslator/translator/translator.py#L29), where SAM iterates through the
7
+
template and acts on `AWS::Serverless::*` Type Resources.
Copy file name to clipboardExpand all lines: docs/safe_lambda_deployments.rst
+21-21Lines changed: 21 additions & 21 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,14 +3,14 @@ Safe Lambda deployments
3
3
4
4
.. contents::
5
5
6
-
Pushing to production can be nerve-racking even if you have 100% unit test coverage and state-of-art full CD system.
6
+
Pushing to production can be nerve-wracking even if you have 100% unit test coverage and a state-of-art full CD system.
7
7
It is a good practice to expose your new code to a small percentage of production traffic, run tests, watch for alarms
8
8
and dial up traffic as you gain more confidence. The goal is to minimize production impact as much as possible.
9
9
10
10
To enable traffic shifting deployments for Lambda functions, we will use Lambda Aliases, which can balance incoming
11
11
traffic between two different versions of your function, based on preassigned weights. Before deployment,
12
12
the alias sends 100% of invokes to the version used in production. During deployment, we will upload the code to Lambda,
13
-
publish a new version, send a small percentage of traffic to new version, monitor, and validate before shifting
13
+
publish a new version, send a small percentage of traffic to the new version, monitor, and validate before shifting
14
14
100% of traffic to the new version. You can do this manually by calling Lambda APIs or let AWS CodeDeploy automate
15
15
it for you. CodeDeploy will shift traffic, monitor alarms, run validation logic and even trigger an automatic rollback
16
16
if something goes wrong.
@@ -32,24 +32,24 @@ Instant traffic shifting using Lambda Aliases
32
32
---------------------------------------------
33
33
34
34
Every Lambda function can have any number of Versions and Aliases
35
-
associated with them. Versions are immutable snapshot of function
35
+
associated with them. Versions are immutable snapshots of a function
36
36
including code & configuration. If you are familiar with git, they are
37
-
similar to commits. It is a good practice in general to publish a new
37
+
similar to commits. In general, it is a good practice to publish a new
38
38
version every time you update your function code. When you invoke a
39
-
specific version (using function name + version number combination) you
40
-
are guaranteed to get the same code & configuration irrespective of
39
+
specific version (using the function name + version number combination) you
40
+
are guaranteed to get the same code & configuration irrespective of the
41
41
state of the function. This protects you against accidentally updating
42
42
production code.
43
43
44
44
To effectively use the versions, you should create an Alias which is
45
45
literally a pointer to a version. Aliases have a name and an ARN similar
46
-
to the function and accepted by the Invoke APIs. If you invoke an Alias,
46
+
to the function and are accepted by the Invoke APIs. If you invoke an Alias,
47
47
Lambda will in turn invoke the version that the Alias is pointing to.
48
48
49
49
In production, you will first update your function code, publish a new
50
-
version, invoke the version directly to run tests against it, and after
51
-
you are satisfied flip the Alias to point to the new version. Traffic
52
-
will instantly shift from using your old version to the new version.
50
+
version, invoke the version directly to run tests against it, and, after
51
+
you are satisfied, flip the Alias to point to the new version. Traffic
52
+
will instantly shift from using your old version to using the new version.
53
53
54
54
SAM provides a simple primitive to do this for you. Add the following
55
55
property to your ``AWS::Serverless::Function`` resource:
@@ -61,10 +61,10 @@ property to your ``AWS::Serverless::Function`` resource:
61
61
This will:
62
62
63
63
- Create an Alias with ``<alias-name>``
64
-
- Creates & publishes a Lambda version with the latest code & configuration
65
-
derived from ``CodeUri`` property
64
+
- Create & publish a Lambda version with the latest code & configuration
65
+
derived from the ``CodeUri`` property
66
66
- Point the Alias to the latest published version
67
-
- Point all event sources to the Alias & not the function
67
+
- Point all event sources to the Alias & not to the function
68
68
- When the ``CodeUri`` property of ``AWS::Serverless::Function`` changes,
69
69
SAM will automatically publish a new version & point the alias to the
70
70
new version
@@ -79,8 +79,8 @@ In other words, your traffic will shift "instantly" to your new code.
79
79
Traffic shifting using CodeDeploy
80
80
----------------------------------
81
81
82
-
For production deployments, you want a more controlled traffic shifting
83
-
from old version to new version while monitoring alarms and triggering a
82
+
For production deployments, you may want more controlled traffic shifting
83
+
from an old version to a new version which monitors alarms and triggers a
84
84
rollback if necessary. CodeDeploy is an AWS service which can do this
85
85
for you. It uses Lambda Alias' ability to route a percentage of traffic
86
86
to two different Lambda Versions. To use this feature, set the
@@ -174,14 +174,14 @@ CloudFormation, the following happens:
174
174
- Before traffic shifting starts, CodeDeploy will invoke the **PreTraffic Hook** Lambda function. This Lambda function must call back to CodeDeploy with an explicit status of Success or Failure, via the PutLifecycleEventHookExecutionStatus_ API. On Failure, CodeDeploy will abort and report a failure back to CloudFormation. On Success, CodeDeploy will proceed with the specified traffic shifting. Here_ is a sample Lambda Hook function.
175
175
- ``Type: Linear10PercentEvery10Minutes`` instructs CodeDeploy to start with 10% traffic on new version and add 10% every 10 minutes. It will complete traffic shifting in 100 minutes.
176
176
- 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.
177
-
- 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 Failure. PostTraffic hook is a great place to run integration tests or other validation actions.
177
+
- 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.
178
178
- If everything went well, the Alias will be pointing to the new Lambda Version.
179
179
180
180
NOTE: Verify that your AWS SDK version supports PutLifecycleEventHookExecutionStatus. For example, Python requires SDK version 1.4.8 or newer.
Ex: ``Linear10PercentEvery10Minutes`` will add 10 percentage of traffic every 10 minute to complete in 100 minutes.
209
209
210
-
- **CanaryXPercentYMinutes**: X percent of traffic will be routed to new Version once, and wait for Y minutes in this
211
-
state before sending 100 percent of traffic to new version. Some people call this as Blue/Green deployment.
210
+
- **CanaryXPercentYMinutes**: X percent of traffic will be routed to new version for Y minutes. After Y minutes,
211
+
100 percent of traffic will be sent to new version. Some people call this as Blue/Green deployment.
212
212
213
213
Ex: ``Canary10Percent15Minutes`` will send 10 percent traffic to new version and 15 minutes later complete deployment
214
214
by sending all traffic to new version.
@@ -254,8 +254,8 @@ Hooks are extremely powerful because:
254
254
Function). So you can customize the hooks logic to the function that is being deployed.
255
255
256
256
NOTE: If the Hook functions are created by the same SAM template that is deployed, then make sure to turn off
257
-
traffic shifting deployments for the hook functions. Also, the Role SAM generates for a Lambda Execution Role does not include all permissions needed for Per and Post hook functions, since it
258
-
will not contain the necessary permissions to call the CodeDepoloy APIs or Invoke your new Lambda function for testing.
257
+
traffic shifting deployments for the hook functions. Also, the Role SAM generates for a Lambda Execution Role does not include all permissions needed for Pre and Post hook functions, since it
258
+
will not contain the necessary permissions to call the CodeDeploy APIs or Invoke your new Lambda function for testing.
259
259
Instead, use the Policies_ attribute to provide the CodeDeploy and Lambda permissions needed. The example also shows a Policy that provides access to the CodeDeploy resource that SAM automatically generates.
260
260
Finally, use the ``FunctionName`` property to control the exact name of the Lambda function CloudFormation creates. Otherwise, CloudFormation will create your Lambda function with the Stack name and a unique ID added as part of the name.
0 commit comments