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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With