-
Notifications
You must be signed in to change notification settings - Fork 12
/
template-private-api.yaml
149 lines (133 loc) · 5.14 KB
/
template-private-api.yaml
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
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
aws-sam-express-private
SAM Template for private APIs.
# More info about Globals: https://github.com/awslabs/serverless-application-model/blob/master/docs/globals.rst
Globals:
Function:
Timeout: 3
Parameters:
VpcIdParameter:
Type: "AWS::EC2::VPC::Id"
Description: VPC ID in which the VPC Endpoint should be created
VpcAllowedSecurityGroupIdParameter:
Type: "AWS::EC2::SecurityGroup::Id"
Description: Security Group Id that is allowed to communicate to private API gateway
VpcEndpointSubnetIdsParameter:
Type: "List<AWS::EC2::Subnet::Id>"
Description: The ID of one or more subnets in which to create an endpoint network interface
Resources:
SocialEventsFunction:
Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
Properties:
CodeUri: ./
Handler: lambda.handler
Runtime: nodejs8.10
Environment: # More info about Env Vars: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#environment-object
Variables:
PARAM1: VALUE
Events:
APIRoot:
Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
Properties:
Path: /
Method: ANY
RestApiId: !Ref SocialEventsPrivateApi
API:
Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
Properties:
Path: /{proxy+}
Method: ANY
RestApiId: !Ref SocialEventsPrivateApi
SocialEventsApiSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
VpcId: !Ref VpcIdParameter
GroupDescription: Allows access over 443 to a single VPC Security Group
SecurityGroupIngress:
-
IpProtocol: "tcp"
FromPort: 443
ToPort: 443
SourceSecurityGroupId: !Ref VpcAllowedSecurityGroupIdParameter
SocialEventAPIAccessEndpoint:
Type: AWS::EC2::VPCEndpoint
Properties:
VpcId:
Ref: VpcIdParameter
ServiceName: !Sub "com.amazonaws.${AWS::Region}.execute-api"
VpcEndpointType: Interface
PrivateDnsEnabled: true
SubnetIds: !Ref VpcEndpointSubnetIdsParameter
SecurityGroupIds:
-
!Ref SocialEventsApiSecurityGroup
SocialEventsPrivateApi:
Type: AWS::Serverless::Api
Properties:
StageName: Prod
MethodSettings:
- HttpMethod: '*'
ResourcePath: /
LoggingLevel: ERROR
EndpointConfiguration: PRIVATE
Variables:
ServerlessExpressLambdaFunctionName: !Ref SocialEventsFunction
DefinitionBody:
swagger: 2.0
info:
title: SocialEventsPrivateApi
basePath: /Prod
schemes:
- https
x-amazon-apigateway-policy:
Version: "2012-10-17"
Statement:
-
Effect: "Allow"
Principal: "*"
Action:
- "execute-api:Invoke"
Resource: "execute-api:/*"
Condition:
StringEquals:
aws:sourceVpce: !Ref SocialEventAPIAccessEndpoint
paths:
/:
x-amazon-apigateway-any-method:
produces:
- application/json
x-amazon-apigateway-integration:
responses:
default:
statusCode: 200
uri: !Join [ ":", [ !Sub "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/arn:aws:lambda:${AWS::Region}:${AWS::AccountId}", "function:${stageVariables.ServerlessExpressLambdaFunctionName}/invocations"] ]
passthroughBehavior: when_no_match
httpMethod: POST
type: aws_proxy
/{proxy+}:
x-amazon-apigateway-any-method:
produces:
- application/json
parameters:
- name: proxy
in: path
required: true
type: string
x-amazon-apigateway-integration:
uri: !Join [ ":", [ !Sub "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/arn:aws:lambda:${AWS::Region}:${AWS::AccountId}", "function:${stageVariables.ServerlessExpressLambdaFunctionName}/invocations"] ]
httpMethod: POST
type: aws_proxy
x-amazon-apigateway-binary-media-types:
- '*/*'
Outputs:
SocialEventsPrivateApi:
Description: "API Gateway endpoint URL for Prod stage"
Value: !Sub "https://${SocialEventsPrivateApi}.execute-api.${AWS::Region}.amazonaws.com/Prod/"
SocialEventsFunction:
Description: "Social Events Lambda Function ARN"
Value: !GetAtt SocialEventsFunction.Arn
SocialEventsFunctionIamRole:
Description: "Implicit IAM Role created for Social Events function"
Value: !GetAtt SocialEventsFunction.Arn