Ref returns a parameter's value or a resource's default identifier, which each type defines: the name of a table or bucket, the ID of a VPC, the ARN of an SNS topic. Fn::GetAtt returns another attribute the type publishes (its read-only properties, Registry and Providers), written !GetAtt Resource.Attribute or !GetAtt [Resource, Attribute]. Both also make one resource wait for the other (Dependency Graph). The template infra/functions.yaml shows each function as an output; this slice and those in Sub, Join and Select and Pseudo Parameters in Templates are the whole file:
AWSTemplateFormatVersion: "2010-09-09"
Parameters:
Stage: {Type: String, AllowedValues: [dev, prod], Default: dev}
Resources:
BooksTable:
Type: AWS::DynamoDB::Table
Properties:
TableName: !Sub booknest-${Stage}-fn-books
BillingMode: PAY_PER_REQUEST
AttributeDefinitions: [{AttributeName: id, AttributeType: N}]
KeySchema: [{AttributeName: id, KeyType: HASH}]
FrontEndBucket:
Type: AWS::S3::Bucket
Outputs:
TableRef: {Value: !Ref BooksTable}
TableArn: {Value: !GetAtt BooksTable.Arn}
BucketRef: {Value: !Ref FrontEndBucket}
BucketDomain: {Value: !GetAtt FrontEndBucket.RegionalDomainName}cd ~/v5-ch7/booknest/infra
aws cloudformation deploy --stack-name booknest-fn --template-file functions.yaml
aws cloudformation describe-stacks --stack-name booknest-fn --output text \
--query 'Stacks[0].Outputs[].[OutputKey,OutputValue]'Waiting for changeset to be created.. Waiting for stack create/update to complete Successfully created/updated stack - booknest-fn AccountId 000000000000 BucketDomain booknest-fn-frontendbucket-9ab3d0c6.s3.localhost.localstack.cloud BucketRef booknest-fn-frontendbucket-9ab3d0c6 BuiltArn arn:aws:dynamodb:us-east-1:000000000000:table/booknest-dev-fn-books Label booknest-fn in us-east-1a Partition aws Region us-east-1 SiteUrl https://booknest-fn-frontendbucket-9ab3d0c6.s3.localhost.localstack.cloud/index.html StackUuid 0e9cfab0-9804-4d6a-8fde-652917631f6f TableArn arn:aws:dynamodb:us-east-1:000000000000:table/booknest-dev-fn-books TableRef booknest-dev-fn-books UrlSuffix localhost.localstack.cloud Zones us-east-1a, us-east-1b, us-east-1c, us-east-1d, us-east-1e, us-east-1f
The same Ref gave a table name and a generated bucket name. On AWS 24 , RegionalDomainName ends in s3.us-east-1.amazonaws.com; LocalStack 63,725 answers with its own domain. cfn-lint 2,641 checks attribute names against the schema: !GetAtt BooksTable.Name fails with E6101 'Name' is not one of ['Arn', 'StreamArn'], and StreamArn exists only once the table has a StreamSpecification.