-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserverless.yml
171 lines (165 loc) · 5.38 KB
/
serverless.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
org: johnbelisle
app: serverless-ddns
service: serverless-ddns
# You can pin your service to only deploy with a specific Serverless version
# Check out our docs for more details
# frameworkVersion: "=X.X.X"
provider:
name: aws
runtime: nodejs12.x
stage: ${opt:stage, 'dev'}
region: us-east-1
logs:
restApi: true
tracing:
apiGateway: true
lambda: true
custom:
config: ${file(config.${self:provider.stage}.json)}
customDomain:
domainName: ${self:custom.config.apiDomainName}
# stage:
# basePath: api
certificateName: '${self:custom.config.apiDomainName}'
createRoute53Record: true
endpointType: 'edge'
plugins:
- serverless-domain-manager
functions:
echo-ip:
handler: src/echoip.handler
role: basicLambdaRole
memorySize: 128
events:
- http:
path: /
method: GET
update-home-dns:
handler: src/updateHomeDNS.handler
role: lambdaUpdateRoute53Role
memorySize: 128
environment:
DNS_HOST_NAME: ${self:custom.config.ddnsHostName}
TOPIC_ARN: ${self:custom.config.notificationTopicARN}
events:
- http:
path: /
method: POST
authorizer:
type: aws_iam
resources:
Resources:
basicLambdaRole:
Type: AWS::IAM::Role
Properties:
RoleName: BasicLambdaRoleServerlessDDNS-${self:provider.stage}
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
Action: sts:AssumeRole
Policies:
- PolicyName: BasicLambdaRoleLoggingPolicy-${self:provider.stage}
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- logs:CreateLogGroup
- logs:CreateLogStream
- logs:PutLogEvents
Resource: { "Fn::Join" : ["", ["arn:aws:logs:",{"Ref":"AWS::Region"},":",{"Ref":"AWS::AccountId"},":log-group:/aws/lambda/*:*"]]}
- Effect: Allow
Action:
- xray:PutTraceSegments
Resource:
- "*"
lambdaUpdateRoute53Role:
Type: AWS::IAM::Role
Properties:
RoleName: UpdateLambdaRoleServerlessDDNS-${self:provider.stage}
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
Action: sts:AssumeRole
Policies:
- PolicyName: UpdateRoute53LambdaRolePolicy-${self:provider.stage}
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- logs:CreateLogGroup
- logs:CreateLogStream
- logs:PutLogEvents
Resource: { "Fn::Join" : ["", ["arn:aws:logs:",{"Ref":"AWS::Region"},":",{"Ref":"AWS::AccountId"},":log-group:/aws/lambda/*:*"]]}
- Effect: Allow
Action:
- route53:ListHostedZones
- route53:ChangeResourceRecordSets
- route53:ListResourceRecordSets
Resource:
- "*"
- Effect: Allow
Action:
- sns:Publish
- sns:Subscribe
Resource: arn:aws:sns:us-east-1:197556904653:NotifyMe
- Effect: Allow
Action:
- xray:PutTraceSegments
Resource:
- "*"
InvokeUpdateHomeDDNSAPIPolicy:
Type: "AWS::IAM::ManagedPolicy"
Properties:
Description: "Policy for allowing invoke access to the updateHomeDDNS secured API"
PolicyDocument:
Version: '2012-10-17'
Statement:
Effect: Allow
Action: execute-api:Invoke
Resource: { "Fn::Join" : ["", ["arn:aws:execute-api:",{"Ref":"AWS::Region"},":",{"Ref":"AWS::AccountId"},":",{"Ref":"ApiGatewayRestApi"},"/*"]]}
APIUser:
Type: "AWS::IAM::User"
Properties:
ManagedPolicyArns:
- { "Ref": "InvokeUpdateHomeDDNSAPIPolicy" }
UserName: update-homeddns-api-user-${self:provider.stage}
MockResource:
Type: AWS::ApiGateway::Resource
Properties:
ParentId:
Fn::GetAtt:
- ApiGatewayRestApi # our default Rest API logical ID
- RootResourceId
PathPart: favicon.ico # the endpoint in your API that is set as proxy
RestApiId:
Ref: ApiGatewayRestApi
MockMethod:
Type: AWS::ApiGateway::Method
Properties:
AuthorizationType: None
HttpMethod: GET
ResourceId:
Ref: MockResource
RestApiId:
Ref: ApiGatewayRestApi
MethodResponses:
- StatusCode: 200
Integration:
RequestTemplates:
application/json: |
{"statusCode": 200}
Type: MOCK
IntegrationResponses:
- ResponseTemplates:
application/json: ''
StatusCode: 200