Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Support both 'VPCEndpointIds' and 'VpcEndpointIds' #3315

Merged
merged 2 commits into from
Aug 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions samtranslator/model/api/api_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -1326,8 +1326,19 @@ def _set_endpoint_configuration(self, rest_api: ApiGatewayRestApi, value: Union[
if isinstance(value, dict) and value.get("Type"):
rest_api.Parameters = {"endpointConfigurationTypes": value.get("Type")}
rest_api.EndpointConfiguration = {"Types": [value.get("Type")]}
if "VPCEndpointIds" in value:
rest_api.EndpointConfiguration["VpcEndpointIds"] = value.get("VPCEndpointIds")

# SAM API `EndpointConfiguration` uses `VPCEndpointIds` but APIGateway RestApi uses `VpcEndpointIds`.
# Deny when both properties are defined at the same time.
GavinZZ marked this conversation as resolved.
Show resolved Hide resolved
if "VPCEndpointIds" in value and "VpcEndpointIds" in value:
raise InvalidResourceException(
rest_api.logical_id,
"'VPCEndpointIds' and 'VpcEndpointIds' cannot be used together in EndpointConfiguration.",
)
# Accept when either `VPCEndpointIds` or `VpcEndpointIds` is defined by users
if "VPCEndpointIds" in value or "VpcEndpointIds" in value:
rest_api.EndpointConfiguration["VpcEndpointIds"] = value.get("VPCEndpointIds") or value.get(
"VpcEndpointIds"
)
else:
rest_api.EndpointConfiguration = {"Types": [value]}
rest_api.Parameters = {"endpointConfigurationTypes": value}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Resources:
ExplicitApiWithVpcEndpointIds:
Type: AWS::Serverless::Api
Properties:
StageName: Prod
DefinitionUri: s3://sam-demo-bucket/webpage_swagger.json
EndpointConfiguration:
Type: PRIVATE
VpcEndpointIds:
- vpc-1

ExplicitApiWithVPCEndpointIds:
Type: AWS::Serverless::Api
Properties:
StageName: Prod
DefinitionUri: s3://sam-demo-bucket/webpage_swagger.json
EndpointConfiguration:
Type: PRIVATE
VPCEndpointIds:
- vpc-2
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Resources:
ExplicitApi:
Type: AWS::Serverless::Api
Properties:
StageName: Prod
DefinitionUri: s3://sam-demo-bucket/webpage_swagger.json
EndpointConfiguration:
Type: PRIVATE
VPCEndpointIds:
- vpc-1
- vpc-2
VpcEndpointIds:
- vpc-3
- vpc-4
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
{
"Resources": {
"ExplicitApiWithVPCEndpointIds": {
"Properties": {
"BodyS3Location": {
"Bucket": "sam-demo-bucket",
"Key": "webpage_swagger.json"
},
"EndpointConfiguration": {
"Types": [
"PRIVATE"
],
"VpcEndpointIds": [
"vpc-2"
]
},
"Parameters": {
"endpointConfigurationTypes": "PRIVATE"
}
},
"Type": "AWS::ApiGateway::RestApi"
},
"ExplicitApiWithVPCEndpointIdsDeploymentf117c932f7": {
"Properties": {
"Description": "RestApi deployment id: f117c932f75cfa87d23dfed64e9430d0081ef289",
"RestApiId": {
"Ref": "ExplicitApiWithVPCEndpointIds"
},
"StageName": "Stage"
},
"Type": "AWS::ApiGateway::Deployment"
},
"ExplicitApiWithVPCEndpointIdsProdStage": {
"Properties": {
"DeploymentId": {
"Ref": "ExplicitApiWithVPCEndpointIdsDeploymentf117c932f7"
},
"RestApiId": {
"Ref": "ExplicitApiWithVPCEndpointIds"
},
"StageName": "Prod"
},
"Type": "AWS::ApiGateway::Stage"
},
"ExplicitApiWithVpcEndpointIds": {
"Properties": {
"BodyS3Location": {
"Bucket": "sam-demo-bucket",
"Key": "webpage_swagger.json"
},
"EndpointConfiguration": {
"Types": [
"PRIVATE"
],
"VpcEndpointIds": [
"vpc-1"
]
},
"Parameters": {
"endpointConfigurationTypes": "PRIVATE"
}
},
"Type": "AWS::ApiGateway::RestApi"
},
"ExplicitApiWithVpcEndpointIdsDeploymentf117c932f7": {
"Properties": {
"Description": "RestApi deployment id: f117c932f75cfa87d23dfed64e9430d0081ef289",
"RestApiId": {
"Ref": "ExplicitApiWithVpcEndpointIds"
},
"StageName": "Stage"
},
"Type": "AWS::ApiGateway::Deployment"
},
"ExplicitApiWithVpcEndpointIdsProdStage": {
"Properties": {
"DeploymentId": {
"Ref": "ExplicitApiWithVpcEndpointIdsDeploymentf117c932f7"
},
"RestApiId": {
"Ref": "ExplicitApiWithVpcEndpointIds"
},
"StageName": "Prod"
},
"Type": "AWS::ApiGateway::Stage"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
{
"Resources": {
"ExplicitApiWithVPCEndpointIds": {
"Properties": {
"BodyS3Location": {
"Bucket": "sam-demo-bucket",
"Key": "webpage_swagger.json"
},
"EndpointConfiguration": {
"Types": [
"PRIVATE"
],
"VpcEndpointIds": [
"vpc-2"
]
},
"Parameters": {
"endpointConfigurationTypes": "PRIVATE"
}
},
"Type": "AWS::ApiGateway::RestApi"
},
"ExplicitApiWithVPCEndpointIdsDeploymentf117c932f7": {
"Properties": {
"Description": "RestApi deployment id: f117c932f75cfa87d23dfed64e9430d0081ef289",
"RestApiId": {
"Ref": "ExplicitApiWithVPCEndpointIds"
},
"StageName": "Stage"
},
"Type": "AWS::ApiGateway::Deployment"
},
"ExplicitApiWithVPCEndpointIdsProdStage": {
"Properties": {
"DeploymentId": {
"Ref": "ExplicitApiWithVPCEndpointIdsDeploymentf117c932f7"
},
"RestApiId": {
"Ref": "ExplicitApiWithVPCEndpointIds"
},
"StageName": "Prod"
},
"Type": "AWS::ApiGateway::Stage"
},
"ExplicitApiWithVpcEndpointIds": {
"Properties": {
"BodyS3Location": {
"Bucket": "sam-demo-bucket",
"Key": "webpage_swagger.json"
},
"EndpointConfiguration": {
"Types": [
"PRIVATE"
],
"VpcEndpointIds": [
"vpc-1"
]
},
"Parameters": {
"endpointConfigurationTypes": "PRIVATE"
}
},
"Type": "AWS::ApiGateway::RestApi"
},
"ExplicitApiWithVpcEndpointIdsDeploymentf117c932f7": {
"Properties": {
"Description": "RestApi deployment id: f117c932f75cfa87d23dfed64e9430d0081ef289",
"RestApiId": {
"Ref": "ExplicitApiWithVpcEndpointIds"
},
"StageName": "Stage"
},
"Type": "AWS::ApiGateway::Deployment"
},
"ExplicitApiWithVpcEndpointIdsProdStage": {
"Properties": {
"DeploymentId": {
"Ref": "ExplicitApiWithVpcEndpointIdsDeploymentf117c932f7"
},
"RestApiId": {
"Ref": "ExplicitApiWithVpcEndpointIds"
},
"StageName": "Prod"
},
"Type": "AWS::ApiGateway::Stage"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
{
"Resources": {
"ExplicitApiWithVPCEndpointIds": {
"Properties": {
"BodyS3Location": {
"Bucket": "sam-demo-bucket",
"Key": "webpage_swagger.json"
},
"EndpointConfiguration": {
"Types": [
"PRIVATE"
],
"VpcEndpointIds": [
"vpc-2"
]
},
"Parameters": {
"endpointConfigurationTypes": "PRIVATE"
}
},
"Type": "AWS::ApiGateway::RestApi"
},
"ExplicitApiWithVPCEndpointIdsDeploymentf117c932f7": {
"Properties": {
"Description": "RestApi deployment id: f117c932f75cfa87d23dfed64e9430d0081ef289",
"RestApiId": {
"Ref": "ExplicitApiWithVPCEndpointIds"
},
"StageName": "Stage"
},
"Type": "AWS::ApiGateway::Deployment"
},
"ExplicitApiWithVPCEndpointIdsProdStage": {
"Properties": {
"DeploymentId": {
"Ref": "ExplicitApiWithVPCEndpointIdsDeploymentf117c932f7"
},
"RestApiId": {
"Ref": "ExplicitApiWithVPCEndpointIds"
},
"StageName": "Prod"
},
"Type": "AWS::ApiGateway::Stage"
},
"ExplicitApiWithVpcEndpointIds": {
"Properties": {
"BodyS3Location": {
"Bucket": "sam-demo-bucket",
"Key": "webpage_swagger.json"
},
"EndpointConfiguration": {
"Types": [
"PRIVATE"
],
"VpcEndpointIds": [
"vpc-1"
]
},
"Parameters": {
"endpointConfigurationTypes": "PRIVATE"
}
},
"Type": "AWS::ApiGateway::RestApi"
},
"ExplicitApiWithVpcEndpointIdsDeploymentf117c932f7": {
"Properties": {
"Description": "RestApi deployment id: f117c932f75cfa87d23dfed64e9430d0081ef289",
"RestApiId": {
"Ref": "ExplicitApiWithVpcEndpointIds"
},
"StageName": "Stage"
},
"Type": "AWS::ApiGateway::Deployment"
},
"ExplicitApiWithVpcEndpointIdsProdStage": {
"Properties": {
"DeploymentId": {
"Ref": "ExplicitApiWithVpcEndpointIdsDeploymentf117c932f7"
},
"RestApiId": {
"Ref": "ExplicitApiWithVpcEndpointIds"
},
"StageName": "Prod"
},
"Type": "AWS::ApiGateway::Stage"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"_autoGeneratedBreakdownErrorMessage": [
"Invalid Serverless Application Specification document. ",
"Number of errors found: 1. ",
"Resource with id [ExplicitApi] is invalid. ",
"'VPCEndpointIds' and 'VpcEndpointIds' cannot be used together in EndpointConfiguration."
],
"errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [ExplicitApi] is invalid. 'VPCEndpointIds' and 'VpcEndpointIds' cannot be used together in EndpointConfiguration."
}