I am using cloudformation to create a lambda function with API integration and with custom domain name. I already have the necessary certificate setup completed (I am using Regional endpoint). My API has several routes like “payments”, “bdi” etc with a stage name called “test”. Below is my template.yaml.
MyApiGateway:
Type: AWS::Serverless::Api
Properties:
AccessLogSetting:
DestinationArn: !GetAtt MyLogGroupForApi.Arn
Format: $context.extendedRequestId $context.identity.sourceIp
$context.identity.caller $context.identity.user [$context.requestTime]
"$context.httpMethod $context.resourcePath $context.protocol" $context.status
$context.responseLength $context.requestId
Variables:
stageName: test
Domain:
CertificateArn: !Ref Certificate
DomainName: "uat-tests.int.coredev01.svc.com"
Route53:
HostedZoneId: !Ref HostedZoneId
Name:
!Sub
- '${TheEnv}-${TheAppNameForResources}-api'
- TheEnv: !Ref Environment
TheAppNameForResources: !Ref AppNameForResources
TheBucketRegion: !Ref AWS::Region
TracingEnabled: true
OpenApiVersion: 3.0.2
Cors:
AllowHeaders: "'Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-
Token'”
AllowMethods: “‘‘”
AllowOrigin: “‘‘”
StageName: test
Auth:
ResourcePolicy:
CustomStatements:
– Effect: Allow
Principal: “*”
Action: “execute-api:Invoke”
Resource: “execute-api:/test/GET/payments”
APIDnsEntry:
Type: AWS::Route53::RecordSet
Properties:
AliasTarget:
DNSName: "uat-tests.int.coredev01.svc.com"
EvaluateTargetHealth: false
HostedZoneId: !Ref HostedZoneId
Comment: !Sub 'DNS name for ${AppNameForResources} API'
HostedZoneName: !Ref HostedZoneName
Name: "ui-tests.int.coredev01.svc.com"
Type: A
APIBasePathMapping:
Type: AWS::ApiGateway::BasePathMapping
Properties:
DomainName: "uat-tests.int.coredev01.svc.com"
RestApiId: !Ref MyApiGateway
Stage: test
When CFN script is executed, I am getting this error pointing to APIBasePathMapping:
Resource handler returned message: "Invalid stage identifier specified (Service:
ApiGateway, Status Code: 400
If I remove the APIBasePathMapping block, API is created successfully.
My goal is to create a custom domain endpoint for my API stage, so that I can refer the API without the wierd default API name created by AWS.
Not sure if I am missing anything else here?
Any help is much appreciated.