Outputs and Exports

Outputs, Exports and the Metadata Section

Outputs publish the names, ARNs and URLs that people and scripts need. An output with an Export name also becomes readable by other stacks in the same account and region through Fn::ImportValue (Fn::ImportValue); export names must be unique there, so BookNest puts the stage in each. Metadata holds data for tools; its key AWS 24 ::CloudFormation 24 ::Interface groups and orders parameters in the console's form.

infra/booknest-data.yaml: the Outputs and Metadata sectionsYAML
Outputs:
  TableName:
    Value: !Ref BooksTable
    Export: {Name: !Sub "booknest-${Stage}-table-name"}
  TableArn:
    Value: !GetAtt BooksTable.Arn
  BucketName:
    Value: !Ref FrontEndBucket
    Export: {Name: !Sub "booknest-${Stage}-bucket"}
Metadata:
  AWS::CloudFormation::Interface:
    ParameterGroups:
      - {Label: {default: Catalog}, Parameters: [Stage, TableSuffix, ReadCapacity]}
Reading a stack's outputs and the account's exportsShell
aws cloudformation describe-stacks --stack-name booknest-data-prod --output text \
  --query 'Stacks[0].Outputs[].[OutputKey,OutputValue]'
aws cloudformation list-exports --output text --query 'Exports[].[Name,Value]'
Output
BucketName   booknest-data-prod-frontendbucket-b7f291e4
TableArn   arn:aws:dynamodb:us-east-1:000000000000:table/booknest-prod-books
TableName   booknest-prod-books
booknest-dev-bucket   booknest-data-dev-frontendbucket-558c59da
booknest-dev-table-name   booknest-dev-books
booknest-prod-bucket   booknest-data-prod-frontendbucket-b7f291e4
booknest-prod-table-name   booknest-prod-books

Output what consumers need and nothing secret: outputs are visible to anyone who can describe the stack. An exported value cannot be changed or deleted while another stack imports it, a trap The Export Deletion Trap explores.