Skip to content

Commit cb8e179

Browse files
authored
Merge pull request #1524 from scbrown/develop
feat: add support for VPCEndpointIds in EndpointConfiguration
2 parents 11a20ae + 5f22876 commit cb8e179

File tree

12 files changed

+851
-9
lines changed

12 files changed

+851
-9
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
AWSTemplateFormatVersion: '2010-09-09'
2+
Transform: AWS::Serverless-2016-10-31
3+
4+
Description: Example demonstrating API EndpointConfiguration
5+
6+
Parameters:
7+
EndpointConfigType:
8+
Type: String
9+
Default: PRIVATE
10+
VpcEndpointId:
11+
Type: String
12+
13+
Resources:
14+
MyApi:
15+
Type: AWS::Serverless::Api
16+
Properties:
17+
StageName: Prod
18+
EndpointConfiguration:
19+
Type: !Ref EndpointConfigType
20+
VPCEndpointIds:
21+
- !Ref VpcEndpointId

samtranslator/model/api/api_generator.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -290,10 +290,11 @@ def _construct_api_domain(self, rest_api):
290290
if endpoint is None:
291291
endpoint = "REGIONAL"
292292
self.domain["EndpointConfiguration"] = "REGIONAL"
293-
elif endpoint not in ["EDGE", "REGIONAL"]:
293+
elif endpoint not in ["EDGE", "REGIONAL", "PRIVATE"]:
294294
raise InvalidResourceException(
295295
self.logical_id,
296-
"EndpointConfiguration for Custom Domains must be" " one of {}.".format(["EDGE", "REGIONAL"]),
296+
"EndpointConfiguration for Custom Domains must be"
297+
" one of {}.".format(["EDGE", "REGIONAL", "PRIVATE"]),
297298
)
298299

299300
if endpoint == "REGIONAL":
@@ -925,6 +926,11 @@ def _set_endpoint_configuration(self, rest_api, value):
925926
:param rest_api: RestApi resource
926927
:param string/dict value: Value to be set
927928
"""
928-
929-
rest_api.EndpointConfiguration = {"Types": [value]}
930-
rest_api.Parameters = {"endpointConfigurationTypes": value}
929+
if isinstance(value, dict) and value.get("Type"):
930+
rest_api.Parameters = {"endpointConfigurationTypes": value.get("Type")}
931+
rest_api.EndpointConfiguration = {"Types": [value.get("Type")]}
932+
if "VPCEndpointIds" in value.keys():
933+
rest_api.EndpointConfiguration["VpcEndpointIds"] = value.get("VPCEndpointIds")
934+
else:
935+
rest_api.EndpointConfiguration = {"Types": [value]}
936+
rest_api.Parameters = {"endpointConfigurationTypes": value}

samtranslator/model/sam_resources.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,7 @@ class SamApi(SamResourceMacro):
714714
"CacheClusterEnabled": PropertyType(False, is_type(bool)),
715715
"CacheClusterSize": PropertyType(False, is_str()),
716716
"Variables": PropertyType(False, is_type(dict)),
717-
"EndpointConfiguration": PropertyType(False, is_str()),
717+
"EndpointConfiguration": PropertyType(False, one_of(is_str(), is_type(dict))),
718718
"MethodSettings": PropertyType(False, is_type(list)),
719719
"BinaryMediaTypes": PropertyType(False, is_type(list)),
720720
"MinimumCompressionSize": PropertyType(False, is_type(int)),
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
Parameters:
2+
EndpointConfigType:
3+
Type: String
4+
VpcEndpointId:
5+
Type: String
6+
7+
Globals:
8+
Api:
9+
# Overriding this property for Implicit API
10+
EndpointConfiguration:
11+
Type: { "Ref" : "EndpointConfigType" }
12+
VPCEndpointIds:
13+
- { "Ref": "VpcEndpointId" }
14+
Resources:
15+
ImplicitApiFunction:
16+
Type: AWS::Serverless::Function
17+
Properties:
18+
CodeUri: s3://sam-demo-bucket/member_portal.zip
19+
Handler: index.gethtml
20+
Runtime: nodejs12.x
21+
Events:
22+
GetHtml:
23+
Type: Api
24+
Properties:
25+
Path: /
26+
Method: get
27+
28+
ExplicitApi:
29+
Type: AWS::Serverless::Api
30+
Properties:
31+
StageName: Prod
32+
DefinitionUri: s3://sam-demo-bucket/webpage_swagger.json
33+
EndpointConfiguration: SomeValue

tests/translator/output/actual

Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
{
2+
"Parameters": {
3+
"VpcEndpointId": {
4+
"Type": "String"
5+
},
6+
"EndpointConfigType": {
7+
"Type": "String"
8+
}
9+
},
10+
"Resources": {
11+
"ImplicitApiFunction": {
12+
"Type": "AWS::Lambda::Function",
13+
"Properties": {
14+
"Handler": "index.gethtml",
15+
"Code": {
16+
"S3Bucket": "sam-demo-bucket",
17+
"S3Key": "member_portal.zip"
18+
},
19+
"Role": {
20+
"Fn::GetAtt": [
21+
"ImplicitApiFunctionRole",
22+
"Arn"
23+
]
24+
},
25+
"Runtime": "nodejs12.x",
26+
"Tags": [
27+
{
28+
"Value": "SAM",
29+
"Key": "lambda:createdBy"
30+
}
31+
]
32+
}
33+
},
34+
"ImplicitApiFunctionRole": {
35+
"Type": "AWS::IAM::Role",
36+
"Properties": {
37+
"AssumeRolePolicyDocument": {
38+
"Version": "2012-10-17",
39+
"Statement": [
40+
{
41+
"Action": [
42+
"sts:AssumeRole"
43+
],
44+
"Effect": "Allow",
45+
"Principal": {
46+
"Service": [
47+
"lambda.amazonaws.com"
48+
]
49+
}
50+
}
51+
]
52+
},
53+
"ManagedPolicyArns": [
54+
"arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
55+
],
56+
"Tags": [
57+
{
58+
"Value": "SAM",
59+
"Key": "lambda:createdBy"
60+
}
61+
]
62+
}
63+
},
64+
"ExplicitApiDeploymentf117c932f7": {
65+
"Type": "AWS::ApiGateway::Deployment",
66+
"Properties": {
67+
"RestApiId": {
68+
"Ref": "ExplicitApi"
69+
},
70+
"Description": "RestApi deployment id: f117c932f75cfa87d23dfed64e9430d0081ef289",
71+
"StageName": "Stage"
72+
}
73+
},
74+
"ImplicitApiFunctionGetHtmlPermissionProd": {
75+
"Type": "AWS::Lambda::Permission",
76+
"Properties": {
77+
"Action": "lambda:InvokeFunction",
78+
"Principal": "apigateway.amazonaws.com",
79+
"FunctionName": {
80+
"Ref": "ImplicitApiFunction"
81+
},
82+
"SourceArn": {
83+
"Fn::Sub": [
84+
"arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/",
85+
{
86+
"__Stage__": "*",
87+
"__ApiId__": {
88+
"Ref": "ServerlessRestApi"
89+
}
90+
}
91+
]
92+
}
93+
}
94+
},
95+
"ExplicitApi": {
96+
"Type": "AWS::ApiGateway::RestApi",
97+
"Properties": {
98+
"EndpointConfiguration": {
99+
"Types": [
100+
"SomeValue"
101+
]
102+
},
103+
"BodyS3Location": {
104+
"Bucket": "sam-demo-bucket",
105+
"Key": "webpage_swagger.json"
106+
},
107+
"Parameters": {
108+
"endpointConfigurationTypes": "SomeValue"
109+
}
110+
}
111+
},
112+
"ExplicitApiProdStage": {
113+
"Type": "AWS::ApiGateway::Stage",
114+
"Properties": {
115+
"DeploymentId": {
116+
"Ref": "ExplicitApiDeploymentf117c932f7"
117+
},
118+
"RestApiId": {
119+
"Ref": "ExplicitApi"
120+
},
121+
"StageName": "Prod"
122+
}
123+
},
124+
"ServerlessRestApiProdStage": {
125+
"Type": "AWS::ApiGateway::Stage",
126+
"Properties": {
127+
"DeploymentId": {
128+
"Ref": "ServerlessRestApiDeployment62b96c1a61"
129+
},
130+
"RestApiId": {
131+
"Ref": "ServerlessRestApi"
132+
},
133+
"StageName": "Prod"
134+
}
135+
},
136+
"ServerlessRestApiDeployment62b96c1a61": {
137+
"Type": "AWS::ApiGateway::Deployment",
138+
"Properties": {
139+
"RestApiId": {
140+
"Ref": "ServerlessRestApi"
141+
},
142+
"Description": "RestApi deployment id: 62b96c1a611878eefb13e8ef66dbc71b9ba3dd19",
143+
"StageName": "Stage"
144+
}
145+
},
146+
"ServerlessRestApi": {
147+
"Type": "AWS::ApiGateway::RestApi",
148+
"Properties": {
149+
"Body": {
150+
"info": {
151+
"version": "1.0",
152+
"title": {
153+
"Ref": "AWS::StackName"
154+
}
155+
},
156+
"paths": {
157+
"/": {
158+
"get": {
159+
"x-amazon-apigateway-integration": {
160+
"httpMethod": "POST",
161+
"type": "aws_proxy",
162+
"uri": {
163+
"Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations"
164+
}
165+
},
166+
"responses": {}
167+
}
168+
}
169+
},
170+
"swagger": "2.0"
171+
},
172+
"EndpointConfiguration": {
173+
"VpcEndpointIds": [
174+
{
175+
"Ref": "VpcEndpointId"
176+
}
177+
],
178+
"Types": [
179+
{
180+
"Ref": "EndpointConfigType"
181+
}
182+
]
183+
},
184+
"Parameters": {
185+
"endpointConfigurationTypes": [
186+
{
187+
"Ref": "EndpointConfigType"
188+
}
189+
]
190+
}
191+
}
192+
}
193+
}
194+
}

0 commit comments

Comments
 (0)