Journeyman
Journeyman

Reputation: 10281

Output AWS CLI YAML output to console

I am using the AWS CLI and CloudFormation to create a new S3 bucket. Here is my yaml file:

AWSTemplateFormatVersion: '2010-09-09'
Description: Creates an S3 bucket
Parameters:
  BucketName:
    Description: Name of the Bucket
    Type: String

Resources:
  ArtifactBucket:
    Type: AWS::S3::Bucket
    DeletionPolicy: Retain

Outputs:
  ArtifactBucket:
    Value: !Sub ${BucketName}
  BucketArn:  
    Value: !GetAtt ArtifactBucket.Arn
    Description: Arn of the new bucket

I run it with the following cli command in a terminal window:

aws cloudformation deploy --stack-name brendan-s3 \
--template-file ComposeEveryApp/create-s3-bucket.yaml \
--profile compose-staging \
--parameter-overrides BucketName=brendan

Everything works fine. Here is the new bucket displayed in the AWS console: enter image description here I'd like to display the Arn of the new bucket (as shown above) in the terminal window. How do I do that?

Upvotes: 3

Views: 1242

Answers (2)

Marcin
Marcin

Reputation: 238697

You can use describe-stacks command. One of its return values will be outputs of your stack.

Upvotes: 0

stijndepestel
stijndepestel

Reputation: 3564

The command aws cloudformation deploy is only instructing the CloudFormation service to start the deployment and not actually waiting for the deployment to finish. Hence there is no link between the Outputs section and the return value of the command you're executing on the CLI.

If you want the Outputs of a cloudformation stack, you'll have to use the describe-stacks command, and you'll need to combine it with a client side filter using --query if you want to only output that specific value.

You can find more info on this SO question.

Upvotes: 2

Related Questions