Skip to content

Commit 8c8f7b0

Browse files
authored
fix: BasePath not included in AWS::ApiGateway::BasePathMapping when defined as ["/"] (#3740)
1 parent 6468430 commit 8c8f7b0

13 files changed

+2133
-1
lines changed

samtranslator/model/api/api_generator.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -805,7 +805,7 @@ def _create_basepath_mapping(
805805
basepath_mapping.DomainName = ref(api_domain_name)
806806
basepath_mapping.RestApiId = ref(rest_api.logical_id)
807807
basepath_mapping.Stage = ref(rest_api.logical_id + ".Stage")
808-
if basepath:
808+
if basepath is not None:
809809
basepath_mapping.BasePath = basepath
810810
return basepath_mapping
811811

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
Parameters:
2+
MyEdgeDomainName:
3+
Type: String
4+
MyEdgeDomainCert:
5+
Type: String
6+
HostedZoneId:
7+
Type: String
8+
9+
Resources:
10+
MyFunction:
11+
Type: AWS::Serverless::Function
12+
Properties:
13+
InlineCode: |
14+
exports.handler = async (event) => {
15+
const response = {
16+
statusCode: 200,
17+
body: JSON.stringify('Hello from Lambda!'),
18+
};
19+
return response;
20+
};
21+
Handler: index.handler
22+
Runtime: nodejs18.x
23+
Events:
24+
Fetch:
25+
Type: Api
26+
Properties:
27+
RestApiId:
28+
Ref: MyApi
29+
Method: Get
30+
Path: /get
31+
32+
MyApi:
33+
Type: AWS::Serverless::Api
34+
Properties:
35+
OpenApiVersion: 3.0.1
36+
StageName: Prod
37+
Domain:
38+
DomainName:
39+
Ref: MyEdgeDomainName
40+
CertificateArn:
41+
Ref: MyEdgeDomainCert
42+
EndpointConfiguration: EDGE
43+
BasePath:
44+
- /
45+
- /get
46+
Route53:
47+
HostedZoneId:
48+
Ref: HostedZoneId
49+
IpV6: true
50+
Metadata:
51+
SamTransformTest: true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
Parameters:
2+
DomainName:
3+
Type: String
4+
Default: private.example.com
5+
Description: Custom domain name for the API
6+
7+
CertificateArn:
8+
Type: String
9+
Default: another-api-arn
10+
Description: ARN of the ACM certificate for the domain
11+
12+
VpcEndpointId:
13+
Type: String
14+
Default: vpce-abcd1234efg
15+
Description: VPC Endpoint ID for private API access
16+
17+
Resources:
18+
MyApi:
19+
Type: AWS::Serverless::Api
20+
Properties:
21+
StageName: prod
22+
Domain:
23+
DomainName: !Ref DomainName
24+
CertificateArn: !Ref CertificateArn
25+
EndpointConfiguration: PRIVATE
26+
BasePath:
27+
- /
28+
- /post
29+
Policy:
30+
Version: '2012-10-17'
31+
Statement:
32+
- Effect: Allow
33+
Principal: '*'
34+
Action: execute-api:Invoke
35+
Resource: execute-api:/*
36+
- Effect: Deny
37+
Principal: '*'
38+
Action: execute-api:Invoke
39+
Resource: execute-api:/*
40+
Condition:
41+
StringNotEquals:
42+
aws:SourceVpce: !Ref VpcEndpointId
43+
Auth:
44+
ResourcePolicy:
45+
CustomStatements:
46+
- Effect: Allow
47+
Principal: '*'
48+
Action: execute-api:Invoke
49+
Resource: execute-api:/*
50+
- Effect: Deny
51+
Principal: '*'
52+
Action: execute-api:Invoke
53+
Resource: execute-api:/*
54+
Condition:
55+
StringNotEquals:
56+
aws:SourceVpce: !Ref VpcEndpointId
57+
58+
Outputs:
59+
ApiDomainName:
60+
Description: Custom Domain Name for the API
61+
Value: !Ref MyApi.DomainNameV2
62+
63+
ApiEndpoint:
64+
Description: API Gateway endpoint URL
65+
Value: !Sub https://${MyApi}.execute-api.${AWS::Region}.amazonaws.com/prod/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
Parameters:
2+
MyRestRegionalDomainName:
3+
Type: String
4+
MyRestRegionalDomainCert:
5+
Type: String
6+
HostedZoneId:
7+
Type: String
8+
9+
Globals:
10+
Api:
11+
Domain:
12+
DomainName:
13+
Ref: MyRestRegionalDomainName
14+
CertificateArn:
15+
Ref: MyRestRegionalDomainCert
16+
EndpointConfiguration: REGIONAL
17+
MutualTlsAuthentication:
18+
TruststoreUri: ${mtlsuri}
19+
TruststoreVersion: 0
20+
SecurityPolicy: TLS_1_2
21+
BasePath:
22+
- /
23+
- /post
24+
Route53:
25+
HostedZoneId:
26+
Ref: HostedZoneId
27+
28+
Resources:
29+
MyFunction:
30+
Type: AWS::Serverless::Function
31+
Properties:
32+
InlineCode: |
33+
exports.handler = async (event) => {
34+
const response = {
35+
statusCode: 200,
36+
body: JSON.stringify('Hello from Lambda!'),
37+
};
38+
return response;
39+
};
40+
Handler: index.handler
41+
Runtime: nodejs18.x
42+
Events:
43+
ImplicitGet:
44+
Type: Api
45+
Properties:
46+
Method: Get
47+
Path: /get
48+
ImplicitPost:
49+
Type: Api
50+
Properties:
51+
Method: Post
52+
Path: /post
53+
Metadata:
54+
SamTransformTest: true

0 commit comments

Comments
 (0)