Skip to content

Commit 4514dcd

Browse files
authored
chore: merge pull request aws#486 from awslabs/master
* merging commits into develop which were merged direct to master by mistake
2 parents fdf7d4d + 870bdd3 commit 4514dcd

File tree

3 files changed

+74
-0
lines changed

3 files changed

+74
-0
lines changed

docs/safe_lambda_deployments.rst

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,40 @@ resource:
106106
PreTraffic: !Ref PreTrafficLambdaFunction
107107
PostTraffic: !Ref PostTrafficLambdaFunction
108108
109+
AliasErrorMetricGreaterThanZeroAlarm:
110+
Type: "AWS::CloudWatch::Alarm"
111+
Properties:
112+
AlarmDescription: Lambda Function Error > 0
113+
ComparisonOperator: GreaterThanThreshold
114+
Dimensions:
115+
- Name: Resource
116+
Value: !Sub "${MyLambdaFunction}:live"
117+
- Name: FunctionName
118+
Value: !Ref MyLambdaFunction
119+
EvaluationPeriods: 2
120+
MetricName: Errors
121+
Namespace: AWS/Lambda
122+
Period: 60
123+
Statistic: Sum
124+
Threshold: 0
125+
126+
LatestVersionErrorMetricGreaterThanZeroAlarm:
127+
Type: "AWS::CloudWatch::Alarm"
128+
Properties:
129+
AlarmDescription: Lambda Function Error > 0
130+
ComparisonOperator: GreaterThanThreshold
131+
Dimensions:
132+
- Name: Resource
133+
Value: !Ref MyLambdaFunction.Version
134+
- Name: FunctionName
135+
Value: !Ref MyLambdaFunction
136+
EvaluationPeriods: 2
137+
MetricName: Errors
138+
Namespace: AWS/Lambda
139+
Period: 60
140+
Statistic: Sum
141+
Threshold: 0
142+
109143
PreTrafficLambdaFunction:
110144
Type: AWS::Serverless::Function
111145
Properties:
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
packaged.yaml
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
## Schedule example
2+
3+
### Overview
4+
5+
The `ScheduledFunction` is of type `AWS::Serverless::Function`. This is a Serverless Application Model (SAM) resource that expands into multiple (3) top-level CloudFormation resources:
6+
7+
- `AWS::Lambda::Function`
8+
- `AWS::Lambda::Permission`
9+
- `AWS::Events::Rule`
10+
11+
`AWS::Lambda::Function` is the top-level CloudFormation resource to define an Amazon Lambda function. Because we want to schedule the function’s periodic execution, we include an `Events` property on our `AWS::Serverless::Function` resource. This allows us to define the function execution schedule *within* the context of the function’s properties. Behind-the-scenes, the `Events` property expands into a `AWS::Events::Rule` resource with an invocation rate of once every 5 minutes.
12+
13+
Lastly, in order for the CloudWatch Events API to invoke our function, it needs permissions to do so. `AWS::Lambda::Permission` grants CloudWatch Events the permission to invoke our function.
14+
15+
### Deployment
16+
17+
The [AWS SAM CLI](https://github.com/awslabs/aws-sam-cli) builds on top of the SAM specification by providing a single tool to manage the packaging and deployment of serverless applications. Once the `sam` tool is installed, the application deployment process occurs in two phases.
18+
19+
First, use `sam` to upload the binary to S3 and reference it in a newly created `packaged.yaml` CloudFormation configuration.
20+
21+
```bash
22+
$ sam package --s3-bucket test-global-config-us-east-1 \
23+
--template-file template.yaml \
24+
--output-template-file packaged.yaml
25+
```
26+
27+
Before using `sam` to deploy using the contents of `packaged.yaml`, run a quick `diff` to see what changed.
28+
29+
```bash
30+
$ diff template.yaml packaged.yaml
31+
```
32+
33+
Lastly, use `sam` again to deploy the template through a CloudFormation stack named `Test`.
34+
35+
```bash
36+
$ sam deploy --template-file packaged.yaml \
37+
--stack-name Test \
38+
--capabilities CAPABILITY_IAM
39+
```

0 commit comments

Comments
 (0)