Skip to content

Commit d5b9f12

Browse files
committed
feat: add support for IpAddressType
1 parent e5afb37 commit d5b9f12

File tree

13 files changed

+725
-1
lines changed

13 files changed

+725
-1
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[
2+
{
3+
"LogicalResourceId": "MyApi",
4+
"ResourceType": "AWS::ApiGateway::RestApi"
5+
},
6+
{
7+
"LogicalResourceId": "MyApiDeployment",
8+
"ResourceType": "AWS::ApiGateway::Deployment"
9+
},
10+
{
11+
"LogicalResourceId": "MyApiProdStage",
12+
"ResourceType": "AWS::ApiGateway::Stage"
13+
}
14+
]
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
Parameters:
2+
IpAddressType:
3+
Type: String
4+
Default: ipv4
5+
6+
Resources:
7+
MyApi:
8+
Type: AWS::Serverless::Api
9+
Properties:
10+
StageName: Prod
11+
DefinitionUri: ${definitionuri}
12+
EndpointConfiguration:
13+
Type: REGIONAL
14+
IpAddressType: !Ref IpAddressType
15+
Metadata:
16+
SamTransformTest: true
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from unittest.case import skipIf
2+
3+
from integration.config.service_names import REST_API
4+
from integration.helpers.base_test import BaseTest
5+
from integration.helpers.resource import current_region_does_not_support
6+
7+
8+
@skipIf(current_region_does_not_support([REST_API]), "Rest API is not supported in this testing region")
9+
class TestApiWithIpAddressType(BaseTest):
10+
"""
11+
Test AWS::Serverless::Api with IpAddressType in EndpointConfiguration
12+
"""
13+
14+
def test_api_with_ipaddresstype(self):
15+
"""
16+
Creates an API with IpAddressType set to ipv4
17+
"""
18+
parameters = [{"ParameterKey": "IpAddressType", "ParameterValue": "ipv4"}]
19+
self.create_and_verify_stack("single/api_with_ipaddresstype", parameters)
20+
21+
rest_api_id = self.get_physical_id_by_type("AWS::ApiGateway::RestApi")
22+
rest_api = self.client_provider.api_client.get_rest_api(restApiId=rest_api_id)
23+
24+
self.assertEqual(rest_api["endpointConfiguration"]["types"], ["REGIONAL"])
25+
self.assertEqual(rest_api["endpointConfiguration"]["ipAddressType"], "ipv4")

samtranslator/internal/schema_source/aws_serverless_api.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,11 @@ class EndpointConfiguration(BaseModel):
223223
"VPCEndpointIds",
224224
["AWS::ApiGateway::RestApi.EndpointConfiguration", "VpcEndpointIds"],
225225
)
226+
IpAddressType: Optional[PassThroughProp] = passthrough_prop(
227+
ENDPOINT_CONFIGURATION_STEM,
228+
"IpAddressType",
229+
["AWS::ApiGateway::RestApi.EndpointConfiguration", "IpAddressType"],
230+
)
226231

227232

228233
Name = Optional[PassThroughProp]

samtranslator/internal/schema_source/sam-docs.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@
5353
},
5454
"sam-property-api-endpointconfiguration": {
5555
"Type": "The endpoint type of a REST API\\. \n*Valid values*: `EDGE` or `REGIONAL` or `PRIVATE` \n*Type*: String \n*Required*: No \n*AWS CloudFormation compatibility*: This property is passed directly to the [`Types`](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-apigateway-restapi-endpointconfiguration.html#cfn-apigateway-restapi-endpointconfiguration-types) property of the `AWS::ApiGateway::RestApi` `EndpointConfiguration` data type\\.",
56-
"VPCEndpointIds": "A list of VPC endpoint IDs of a REST API against which to create Route53 aliases\\. \n*Type*: List \n*Required*: No \n*AWS CloudFormation compatibility*: This property is passed directly to the [`VpcEndpointIds`](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-apigateway-restapi-endpointconfiguration.html#cfn-apigateway-restapi-endpointconfiguration-vpcendpointids) property of the `AWS::ApiGateway::RestApi` `EndpointConfiguration` data type\\."
56+
"VPCEndpointIds": "A list of VPC endpoint IDs of a REST API against which to create Route53 aliases\\. \n*Type*: List \n*Required*: No \n*AWS CloudFormation compatibility*: This property is passed directly to the [`VpcEndpointIds`](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-apigateway-restapi-endpointconfiguration.html#cfn-apigateway-restapi-endpointconfiguration-vpcendpointids) property of the `AWS::ApiGateway::RestApi` `EndpointConfiguration` data type\\.",
57+
"IpAddressType": "The IP address type for the API Gateway endpoint\\. \n*Valid values*: `ipv4` or `dualstack` \n*Type*: String \n*Required*: No \n*AWS CloudFormation compatibility*: This property is passed directly to the [`IpAddressType`](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-apigateway-restapi-endpointconfiguration.html#cfn-apigateway-restapi-endpointconfiguration-ipaddresstype) property of the `AWS::ApiGateway::RestApi` `EndpointConfiguration` data type\\."
5758
},
5859
"sam-property-api-lambdarequestauthorizationidentity": {
5960
"Context": "Converts the given context strings to the mapping expressions of format `context.contextString`\\. \n*Type*: List \n*Required*: No \n*AWS CloudFormation compatibility*: This property is unique to AWS SAM and doesn't have an AWS CloudFormation equivalent\\.",

samtranslator/model/api/api_generator.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1537,6 +1537,10 @@ def _set_endpoint_configuration(self, rest_api: ApiGatewayRestApi, value: Union[
15371537
rest_api.EndpointConfiguration["VpcEndpointIds"] = value.get("VPCEndpointIds") or value.get(
15381538
"VpcEndpointIds"
15391539
)
1540+
1541+
# Handle IpAddressType if present
1542+
if "IpAddressType" in value:
1543+
rest_api.EndpointConfiguration["IpAddressType"] = value.get("IpAddressType")
15401544
else:
15411545
rest_api.EndpointConfiguration = {"Types": [value]}
15421546
rest_api.Parameters = {"endpointConfigurationTypes": value}

samtranslator/schema/schema.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6478,6 +6478,11 @@
64786478
"AWS::ApiGateway::RestApi.EndpointConfiguration": {
64796479
"additionalProperties": false,
64806480
"properties": {
6481+
"IpAddressType": {
6482+
"markdownDescription": "The IP address types that can invoke an API (RestApi). Use `ipv4` to allow only IPv4 addresses to invoke an API, or use `dualstack` to allow both IPv4 and IPv6 addresses to invoke an API. For the `PRIVATE` endpoint type, only `dualstack` is supported.",
6483+
"title": "IpAddressType",
6484+
"type": "string"
6485+
},
64816486
"Types": {
64826487
"items": {
64836488
"type": "string"
@@ -274565,6 +274570,11 @@
274565274570
"EndpointConfiguration": {
274566274571
"additionalProperties": false,
274567274572
"properties": {
274573+
"IpAddressType": {
274574+
"markdownDescription": "The IP address type for the API Gateway endpoint\\. \n*Valid values*: `ipv4` or `dualstack` \n*Type*: String \n*Required*: No \n*AWS CloudFormation compatibility*: This property is passed directly to the [`IpAddressType`](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-apigateway-restapi-endpointconfiguration.html#cfn-apigateway-restapi-endpointconfiguration-ipaddresstype) property of the `AWS::ApiGateway::RestApi` `EndpointConfiguration` data type\\.",
274575+
"title": "IpAddressType",
274576+
"type": "string"
274577+
},
274568274578
"Type": {
274569274579
"items": {
274570274580
"type": "string"

schema_source/cloudformation.schema.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6471,6 +6471,11 @@
64716471
"AWS::ApiGateway::RestApi.EndpointConfiguration": {
64726472
"additionalProperties": false,
64736473
"properties": {
6474+
"IpAddressType": {
6475+
"markdownDescription": "The IP address types that can invoke an API (RestApi). Use `ipv4` to allow only IPv4 addresses to invoke an API, or use `dualstack` to allow both IPv4 and IPv6 addresses to invoke an API. For the `PRIVATE` endpoint type, only `dualstack` is supported.",
6476+
"title": "IpAddressType",
6477+
"type": "string"
6478+
},
64746479
"Types": {
64756480
"items": {
64766481
"type": "string"

schema_source/sam.schema.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1164,6 +1164,23 @@
11641164
"EndpointConfiguration": {
11651165
"additionalProperties": false,
11661166
"properties": {
1167+
"IpAddressType": {
1168+
"__samPassThrough": {
1169+
"markdownDescriptionOverride": "The IP address type for the API Gateway endpoint\\. \n*Valid values*: `ipv4` or `dualstack` \n*Type*: String \n*Required*: No \n*AWS CloudFormation compatibility*: This property is passed directly to the [`IpAddressType`](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-apigateway-restapi-endpointconfiguration.html#cfn-apigateway-restapi-endpointconfiguration-ipaddresstype) property of the `AWS::ApiGateway::RestApi` `EndpointConfiguration` data type\\.",
1170+
"schemaPath": [
1171+
"definitions",
1172+
"AWS::ApiGateway::RestApi.EndpointConfiguration",
1173+
"properties",
1174+
"IpAddressType"
1175+
]
1176+
},
1177+
"allOf": [
1178+
{
1179+
"$ref": "#/definitions/PassThroughProp"
1180+
}
1181+
],
1182+
"title": "IpAddressType"
1183+
},
11671184
"Type": {
11681185
"__samPassThrough": {
11691186
"markdownDescriptionOverride": "The endpoint type of a REST API\\. \n*Valid values*: `EDGE` or `REGIONAL` or `PRIVATE` \n*Type*: String \n*Required*: No \n*AWS CloudFormation compatibility*: This property is passed directly to the [`Types`](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-apigateway-restapi-endpointconfiguration.html#cfn-apigateway-restapi-endpointconfiguration-types) property of the `AWS::ApiGateway::RestApi` `EndpointConfiguration` data type\\.",
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
Parameters:
2+
EndpointConfigType:
3+
Type: String
4+
IpAddressType:
5+
Type: String
6+
Default: ipv4
7+
AllowedValues:
8+
- ipv4
9+
- dualstack
10+
11+
Globals:
12+
Api:
13+
# Overriding this property for Implicit API
14+
EndpointConfiguration:
15+
Type: {Ref: EndpointConfigType}
16+
IpAddressType: {Ref: IpAddressType}
17+
18+
Resources:
19+
ImplicitApiFunction:
20+
Type: AWS::Serverless::Function
21+
Properties:
22+
CodeUri: s3://sam-demo-bucket/member_portal.zip
23+
Handler: index.gethtml
24+
Runtime: nodejs12.x
25+
Events:
26+
GetHtml:
27+
Type: Api
28+
Properties:
29+
Path: /
30+
Method: get
31+
32+
ExplicitApi:
33+
Type: AWS::Serverless::Api
34+
Properties:
35+
StageName: Prod
36+
DefinitionUri: s3://sam-demo-bucket/webpage_swagger.json
37+
EndpointConfiguration:
38+
Type: REGIONAL
39+
IpAddressType: ipv4

0 commit comments

Comments
 (0)