Skip to content

fix: BasePath not included in AWS::ApiGateway::BasePathMapping when defined as ["/"] #3740

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

Merged
merged 3 commits into from
Mar 26, 2025
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
2 changes: 1 addition & 1 deletion samtranslator/model/api/api_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,7 @@ def _create_basepath_mapping(
basepath_mapping.DomainName = ref(api_domain_name)
basepath_mapping.RestApiId = ref(rest_api.logical_id)
basepath_mapping.Stage = ref(rest_api.logical_id + ".Stage")
if basepath:
if basepath is not None:
basepath_mapping.BasePath = basepath
return basepath_mapping

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
Parameters:
MyEdgeDomainName:
Type: String
MyEdgeDomainCert:
Type: String
HostedZoneId:
Type: String

Resources:
MyFunction:
Type: AWS::Serverless::Function
Properties:
InlineCode: |
exports.handler = async (event) => {
const response = {
statusCode: 200,
body: JSON.stringify('Hello from Lambda!'),
};
return response;
};
Handler: index.handler
Runtime: nodejs18.x
Events:
Fetch:
Type: Api
Properties:
RestApiId:
Ref: MyApi
Method: Get
Path: /get

MyApi:
Type: AWS::Serverless::Api
Properties:
OpenApiVersion: 3.0.1
StageName: Prod
Domain:
DomainName:
Ref: MyEdgeDomainName
CertificateArn:
Ref: MyEdgeDomainCert
EndpointConfiguration: EDGE
BasePath:
- /
- /get
Route53:
HostedZoneId:
Ref: HostedZoneId
IpV6: true
Metadata:
SamTransformTest: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
Parameters:
DomainName:
Type: String
Default: private.example.com
Description: Custom domain name for the API

CertificateArn:
Type: String
Default: another-api-arn
Description: ARN of the ACM certificate for the domain

VpcEndpointId:
Type: String
Default: vpce-abcd1234efg
Description: VPC Endpoint ID for private API access

Resources:
MyApi:
Type: AWS::Serverless::Api
Properties:
StageName: prod
Domain:
DomainName: !Ref DomainName
CertificateArn: !Ref CertificateArn
EndpointConfiguration: PRIVATE
BasePath:
- /
- /post
Policy:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal: '*'
Action: execute-api:Invoke
Resource: execute-api:/*
- Effect: Deny
Principal: '*'
Action: execute-api:Invoke
Resource: execute-api:/*
Condition:
StringNotEquals:
aws:SourceVpce: !Ref VpcEndpointId
Auth:
ResourcePolicy:
CustomStatements:
- Effect: Allow
Principal: '*'
Action: execute-api:Invoke
Resource: execute-api:/*
- Effect: Deny
Principal: '*'
Action: execute-api:Invoke
Resource: execute-api:/*
Condition:
StringNotEquals:
aws:SourceVpce: !Ref VpcEndpointId

Outputs:
ApiDomainName:
Description: Custom Domain Name for the API
Value: !Ref MyApi.DomainNameV2

ApiEndpoint:
Description: API Gateway endpoint URL
Value: !Sub https://${MyApi}.execute-api.${AWS::Region}.amazonaws.com/prod/
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
Parameters:
MyRestRegionalDomainName:
Type: String
MyRestRegionalDomainCert:
Type: String
HostedZoneId:
Type: String

Globals:
Api:
Domain:
DomainName:
Ref: MyRestRegionalDomainName
CertificateArn:
Ref: MyRestRegionalDomainCert
EndpointConfiguration: REGIONAL
MutualTlsAuthentication:
TruststoreUri: ${mtlsuri}
TruststoreVersion: 0
SecurityPolicy: TLS_1_2
BasePath:
- /
- /post
Route53:
HostedZoneId:
Ref: HostedZoneId

Resources:
MyFunction:
Type: AWS::Serverless::Function
Properties:
InlineCode: |
exports.handler = async (event) => {
const response = {
statusCode: 200,
body: JSON.stringify('Hello from Lambda!'),
};
return response;
};
Handler: index.handler
Runtime: nodejs18.x
Events:
ImplicitGet:
Type: Api
Properties:
Method: Get
Path: /get
ImplicitPost:
Type: Api
Properties:
Method: Post
Path: /post
Metadata:
SamTransformTest: true
Loading