Skip to content

Commit

Permalink
fix: Support both 'VPCEndpointIds' and 'VpcEndpointIds' (aws#3315)
Browse files Browse the repository at this point in the history
  • Loading branch information
GavinZZ committed Aug 22, 2023
1 parent ab1c33b commit e3e2e26
Show file tree
Hide file tree
Showing 7 changed files with 320 additions and 2 deletions.
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.
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."
}

0 comments on commit e3e2e26

Please sign in to comment.