Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get cfnoutputs of AWS stack to a file using AWS-CDK

I want to store the Cfnoutputs in AWS-CDK to a file(Python).

Below is the code to show Public IP on console.

my_ip = core.CfnOutput(
    scope=self,
    id="PublicIp",
    value=my_ec2.instance_public_ip, 
    description="public ip of my instance", 
    export_name="my-ec2-public-ip")

I have tried using redirecting the output in Python by using command:

cdk deploy * > file.txt

But no success.

Please help

like image 756
Amit Kanderi Avatar asked Dec 01 '22 13:12

Amit Kanderi


1 Answers

For every value you want saved after the stack is run add a core.CfnOutput call in your code.

Then when you deploy your stack, use:

% cdk deploy {stack-name} --profile $(AWS_PROFILE) --require-approval never \
             --outputs-file {output-json-file}

This deploys the stack, doesn't stop to ask for yes/no approvals (so you can put it in a Makefile or a CI/CD script) and once done, saves the value of every CfnOutput in your stack to a JSON file.

Details here: https://github.com/aws/aws-cdk/commit/75d5ee9e41935a9525fa6cfe5a059398d0a799cd

like image 64
Ramin Avatar answered Dec 06 '22 02:12

Ramin