-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlambda-function-cf.yml
96 lines (95 loc) · 3.05 KB
/
lambda-function-cf.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
Transform: 'AWS::Serverless-2016-10-31'
Globals:
Api:
OpenApiVersion: '3.0.1' ## prevents default stage getting created. (https://github.com/awslabs/serverless-application-model/issues/191)
Parameters:
NamePrefix:
Type: 'String'
Default: 'virtual-number'
LambdaJarName:
Type: 'String'
Environment:
Type: 'String'
Default: 'test'
GatewayStage:
Type: 'String'
Default: 'test'
DefaultVoiceAnswerText:
Type: 'String'
Description: 'The default voice text response which should be spoken when a call is received.'
AccessIp:
Type: 'String'
Conditions:
noAccessIp: !Equals [ !Ref AccessIp, '' ] ## Check if the IP is blank
Resources:
LambdaApiGateway:
Type: AWS::Serverless::Api
Properties:
Name: !Sub "${Environment}-${NamePrefix}-lambda-api-gateway"
StageName: !Ref 'GatewayStage'
EndpointConfiguration: REGIONAL
## AWS::ApiGateway::Stage
MethodSettings:
-
ResourcePath: "/*"
HttpMethod: "*"
ThrottlingRateLimit: 50
ThrottlingBurstLimit: 25
Auth:
ResourcePolicy:
CustomStatements:
-
Effect: 'Allow'
Principal: '*'
Action: 'execute-api:Invoke'
Resource:
- 'execute-api:/*/*/*'
Condition:
IpAddress:
aws:SourceIp:
- '119.81.44.0/28' ## Nexmo access IPs
- '169.60.146.16/28' ## Nexmo access IPs
- '169.63.86.160/28' ## Nexmo access IPs
- '5.10.112.112/28' ## Nexmo access IPs
- '169.50.200.64/28' ## Nexmo access IPs
- !If
- noAccessIp
- !Ref AWS::NoValue
- Effect: 'Allow'
Principal: '*'
Action: 'execute-api:Invoke'
Resource:
- 'execute-api:/*/*/*'
Condition:
IpAddress:
aws:SourceIp:
- !Ref 'AccessIp'
LambdaFunction:
Type: 'AWS::Serverless::Function'
Properties:
FunctionName: !Sub "${Environment}-${NamePrefix}-lambda-function"
Description: "A lambda function which accepts incoming phone calls and builds a call-plan definition for the call to follow."
Handler: 'io.bluurr.forward.AwsApiGatewayHandler'
CodeUri:
Key: !Ref 'LambdaJarName'
Bucket:
Fn::ImportValue: !Sub "${Environment}-${NamePrefix}-lambda-s3-bucket"
Environment:
Variables:
default_voice_answer_text: !Ref 'DefaultVoiceAnswerText'
Runtime: java8
MemorySize: 1024
Timeout: 30
Events:
Api:
Type: Api
Properties:
RestApiId: !Ref LambdaApiGateway
Path: /call-event
Method: post
Outputs:
LambdaApiGateway:
Description: The Api gateway for calling the lambda function.
Value: !Ref LambdaApiGateway
Export:
Name: !Sub "${Environment}-${NamePrefix}-lambda-api-gateway"