serverless-application-model
serverless-application-model copied to clipboard
Unable to obtain RegionalDomainName and RegionalHostedZoneId from generated CustomDomain object.
Description:
When trying out the new Domain object for AWS::Serverless::Api in v1.20 I found that the AWS::ApiGateway::DomainName resource that's generated uses a random identifier appended onto the logical ID.
Example: ApiGatewayDomainNamef5d64213a3
This resource also doesn't use the parent API resource name as a prefix like with other generated resources like the BasePathMapping and ProdStage.
This makes it where I cannot perform a !GetAtt on the autogenerated resource to obtain the domain and hosted zone values to generate a Route 53 record.
My use case for not using the built-in option to create records is using alternative routing strategies (like latency based routing using SetId).
@brysontyrrell This is a referable property, just like Deployment and Stage. So you can get the name via !Ref ApiName.DomainName. Please lmk if that works!
Please document this.
Does anyone know the referrable property for the hosted zone id ? Haven't been able to track that one down yet.
@flagscript SAM doesnt create HostedZone resource for you. You can read more about the hosted zone cfn resource here
Apologies - I think I didn't describe it well. :)
I'm assuming this creates a AWS::ApiGateway::DomainName under the covers. Currently we need to update the R53 Alias record in another account with the RegionalDomainName and RegionalHostedZoneId created by that resource.
We're just currently creating our own AWS::ApiGateway::DomainName and attaching it to the AWS::Serverless::Api directly so we can get these values. I was wondering if there is any shorthand like the !Ref RestApi.Stage we can use to get these values (something like !Ref RestApi.RegionalDomainName) just because the Domain Property syntax would be so much prettier to use and would love to switch to it.
@flagscript I had the same issue and just found a solution. You can do:
DNSName: !GetAtt [Api.DomainName, RegionalDomainName]
HostedZoneId: !GetAtt [Api.DomainName, RegionalHostedZoneId]
for me this was a permissions issue:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AllowCloudFrontUpdateDistribution",
"Effect": "Allow",
"Action": [
"cloudfront:*"
],
"Resource": [
"*"
]
}
]
}
We document this usage here (also linked from the top of resource documentation):
AWS::Serverless::Api: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-specification-generated-resources-api.html#sam-specification-generated-resources-api-domain-nameAWS::Serverless::HttpApi: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-specification-generated-resources-httpapi.html#sam-specification-generated-resources-httpapi-domain-name
So you can access attributes using e.g. !GetAtt <api-logical-id>.DomainName.RegionalDomainName.