Skip to content

Commit dd5d5c6

Browse files
author
Frank Schmid
committed
Sample branch with warmup plugin, APIG and resource changes
1 parent 5aff764 commit dd5d5c6

File tree

2 files changed

+43
-27
lines changed

2 files changed

+43
-27
lines changed

handlers/testfct1/handler.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
import { Test1 } from '../../src/test1';
44

55
export function handle(event, context) {
6+
7+
if (event.source === "serverless-plugin-warmup") {
8+
console.log("Warmup request."); // eslint-disable-line no-console
9+
return context.done(null, "Lambda is warm.");
10+
}
11+
612
Test1.run(event).asCallback(context.done);
713
return; // no Promise return as we invoke `context.done` directly!
814
}

serverless.yml

Lines changed: 37 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,32 @@ provider:
99
memorySize: 512
1010
timeout: 15
1111

12+
vpc:
13+
securityGroupIds:
14+
- 'Fn::ImportValue': ${self:custom.networkStack}-PrivateSG
15+
subnetIds:
16+
- 'Fn::ImportValue': ${self:custom.networkStack}-PrivateSubnet1
17+
- 'Fn::ImportValue': ${self:custom.networkStack}-PrivateSubnet2
18+
1219
iamRoleStatements:
13-
- Effect: Allow # access to DynamoDB
20+
- Effect: Allow # access to API Gateway
21+
Action:
22+
- execute-api:Invoke
23+
Resource:
24+
# Allow access to our own APIs
25+
- 'Fn::Join':
26+
- ':'
27+
-
28+
- arn:aws:execute-api
29+
- Ref: 'AWS::Region'
30+
- Ref: 'AWS::AccountId'
31+
- 'Fn::Join':
32+
- '/'
33+
-
34+
- Ref: ApiGatewayRestApi
35+
- '*/*/*'
36+
- Effect: Allow
37+
# access to DynamoDB
1438
Action:
1539
- dynamodb:*
1640
Resource:
@@ -43,12 +67,18 @@ provider:
4367
plugins:
4468
- serverless-offline
4569
- serverless-webpack
70+
- serverless-plugin-warmup
4671
- serverless-aws-alias
4772

4873
custom:
4974
stage: ${opt:stage, self:provider.stage}
5075
region: ${opt:region, self:provider.region}
5176

77+
# Stack names for references
78+
networkStack: stashimi-${self:custom.stage}
79+
80+
newService: ${self:}
81+
5282
# Stage dependent variables.
5383
# Usage: ${self:custom.${self:custom.stage}.<varname>}
5484
dev:
@@ -64,38 +94,18 @@ functions:
6494
testfct1:
6595
description: 'Echo function echoes alias'
6696
handler: handlers/testfct1/handler.handle
97+
warmup: true
6798
events:
6899
- http:
69100
method: GET
70101
path: /func1
71-
- stream:
72-
type: dynamodb
73-
arn:
74-
Fn::GetAtt:
75-
- TestDynamoDbTable
76-
- StreamArn
102+
# authorizer:
103+
# name: myAuth
104+
# identitySource: method.request.header.Authorization
105+
# resultTtlInSeconds: 0
106+
# arn: arn:aws:lambda:us-east-1:XXXXXXX:function:profile-access-token
77107

78108
resources:
79109
Resources:
80110

81-
TestDynamoDbTable:
82-
Type: AWS::DynamoDB::Table
83-
DeletionPolicy: Delete
84-
Properties:
85-
AttributeDefinitions:
86-
- AttributeName: myKey
87-
AttributeType: S
88-
KeySchema:
89-
- AttributeName: myKey
90-
KeyType: HASH
91-
ProvisionedThroughput:
92-
ReadCapacityUnits: 1
93-
WriteCapacityUnits: 1
94-
StreamSpecification:
95-
StreamViewType: NEW_AND_OLD_IMAGES
96-
97111
Outputs:
98-
TestDynamoDbTableName:
99-
Description: Test DynamoDB Table Name
100-
Value:
101-
Ref: TestDynamoDbTable

0 commit comments

Comments
 (0)