Package: aws-cloudformation
Welcome toaws_cloudformationDocumentationAWS CloudFormation deployment for human, Enableterraform plan,terraform applystyled deployment.Features:Preview the change set details before deployment.Automatically upload big template to S3 before deployment, even for nested template.Support SYNC call for deployment and deletion, wait until it success or fail (the original API is ASYNC call).Allow prompt for user to enter “YES” to proceed.Provide hyperlink for one-click to jump to the Console to preview.Table of ContentTalk is cheap, show me the codeInstallTalk is cheap, show me the code⭐Console Output:==============Deploystack:'cottonformation-deploy-stack-test'===============previewstackinAWSCloudFormationconsole:https://console.aws.amazon.com/cloudformation/home?#/stacks?filteringStatus=active&filteringText=cottonformation-deploy-stack-test&viewNested=true&hideStacks=falsepreview**changesetdetails**at:https://us-east-1.console.aws.amazon.com/cloudformation/home?region=us-east-1#/stacks/changesets/changes?stackId=arn:aws:cloudformation:us-east-1:111122223333:stack/cottonformation-deploy-stack-test/0c5596c0-76b4-11ed-92b1-0a0bcad48579&changeSetId=arn:aws:cloudformation:us-east-1:111122223333:changeSet/cottonformation-deploy-stack-test-2022-12-08-04-51-58-892/8c88d0c1-d5c7-495b-820e-29e5752a04d4waitforchangesetcreationtofinish...on1thattempt,elapsed5seconds,remain55seconds...reachedstatusCREATE_COMPLETE+----------------------------ChangeSetStatistics-----------------------------|🟢Add1Resource|+--------------------------------------------------------------------------------+-----------------------------------Changes------------------------------------|🟢📦AddResource:Secret1AWS::SecretsManager::Secret|+--------------------------------------------------------------------------------needtoexecutethechangesettoapplythosechanges.preview**createstackprogress**at:https://us-east-1.console.aws.amazon.com/cloudformation/home?region=us-east-1#/stacks/stackinfo?filteringText=cottonformation-deploy-stack-test&viewNested=true&hideStacks=false&stackId=arn:aws:cloudformation:us-east-1:111122223333:stack/cottonformation-deploy-stack-test/0c5596c0-76b4-11ed-92b1-0a0bcad48579&filteringStatus=activewaitfordeploytofinish...on2thattempt,elapsed10seconds,remain50seconds...reachedstatus🟢'CREATE_COMPLETE'done==============Deploystack:'cottonformation-deploy-stack-test'===============previewstackinAWSCloudFormationconsole:https://console.aws.amazon.com/cloudformation/home?#/stacks?filteringStatus=active&filteringText=cottonformation-deploy-stack-test&viewNested=true&hideStacks=falsepreview**changesetdetails**at:https://us-east-1.console.aws.amazon.com/cloudformation/home?region=us-east-1#/stacks/changesets/changes?stackId=arn:aws:cloudformation:us-east-1:111122223333:stack/cottonformation-deploy-stack-test/0c5596c0-76b4-11ed-92b1-0a0bcad48579&changeSetId=arn:aws:cloudformation:us-east-1:111122223333:changeSet/cottonformation-deploy-stack-test-2022-12-08-04-52-39-134/8e1fd139-7a37-43dd-9378-40a328970036waitforchangesetcreationtofinish...on1thattempt,elapsed5seconds,remain55seconds...reachedstatusCREATE_COMPLETE+----------------------------ChangeSetStatistics-----------------------------|🟢Add1Resource|🔵Modify1Resource|+--------------------------------------------------------------------------------+-----------------------------------Changes------------------------------------|🟢📦AddResource:Secret222AWS::SecretsManager::Secret|🔵📦ModifyResource:Secret1AWS::SecretsManager::Secret|🔵💡Properties:Secret1AWS::SecretsManager::Secret.Description|🔵💡Tags:Secret1AWS::SecretsManager::Secret|+--------------------------------------------------------------------------------needtoexecutethechangesettoapplythosechanges.preview**updatestackprogress**at:https://us-east-1.console.aws.amazon.com/cloudformation/home?region=us-east-1#/stacks/stackinfo?filteringText=cottonformation-deploy-stack-test&viewNested=true&hideStacks=false&stackId=arn:aws:cloudformation:us-east-1:111122223333:stack/cottonformation-deploy-stack-test/0c5596c0-76b4-11ed-92b1-0a0bcad48579&filteringStatus=activewaitfordeploytofinish...on3thattempt,elapsed15seconds,remain45seconds...reachedstatus🟢'UPDATE_COMPLETE'done==============Deploystack:'cottonformation-deploy-stack-test'===============previewstackinAWSCloudFormationconsole:https://console.aws.amazon.com/cloudformation/home?#/stacks?filteringStatus=active&filteringText=cottonformation-deploy-stack-test&viewNested=true&hideStacks=falsepreview**changesetdetails**at:https://us-east-1.console.aws.amazon.com/cloudformation/home?region=us-east-1#/stacks/changesets/changes?stackId=arn:aws:cloudformation:us-east-1:111122223333:stack/cottonformation-deploy-stack-test/0c5596c0-76b4-11ed-92b1-0a0bcad48579&changeSetId=arn:aws:cloudformation:us-east-1:111122223333:changeSet/cottonformation-deploy-stack-test-2022-12-08-04-53-07-499/6edbcdf2-8e27-463f-bc5f-35587463fcebwaitforchangesetcreationtofinish...on2thattempt,elapsed10seconds,remain50seconds...reachedstatusCREATE_COMPLETE+----------------------------ChangeSetStatistics-----------------------------|🟢Add1Resource|🔵Modify1Resource|🔴Remove1Resource|+--------------------------------------------------------------------------------+-----------------------------------Changes------------------------------------|🟢📦AddResource:Secret33333AWS::SecretsManager::Secret|🔵📦ModifyResource:Secret222AWS::SecretsManager::Secret|🔵💡Properties:Secret222AWS::SecretsManager::Secret.Description|🔵💡Metadata:Secret222AWS::SecretsManager::Secret|🔵💡CreationPolicy:Secret222AWS::SecretsManager::Secret|🔵💡UpdatePolicy:Secret222AWS::SecretsManager::Secret|🔵💡Tags:Secret222AWS::SecretsManager::Secret|🔴📦RemoveResource:Secret1AWS::SecretsManager::Secret|+--------------------------------------------------------------------------------needtoexecutethechangesettoapplythosechanges.preview**updatestackprogress**at:https://us-east-1.console.aws.amazon.com/cloudformation/home?region=us-east-1#/stacks/stackinfo?filteringText=cottonformation-deploy-stack-test&viewNested=true&hideStacks=false&stackId=arn:aws:cloudformation:us-east-1:111122223333:stack/cottonformation-deploy-stack-test/0c5596c0-76b4-11ed-92b1-0a0bcad48579&filteringStatus=activewaitfordeploytofinish...on3thattempt,elapsed15seconds,remain45seconds...reachedstatus🟢'UPDATE_COMPLETE'done===============Removestack'cottonformation-deploy-stack-test'===============previewstackinAWSCloudFormationconsole:https://console.aws.amazon.com/cloudformation/home?#/stacks?filteringStatus=active&filteringText=cottonformation-deploy-stack-test&viewNested=true&hideStacks=falsewaitfordeletetofinish...on1thattempt,elapsed5seconds,remain55seconds...alreadydeleted.done⭐CloudFormation declaration, seecottonformation:# -*- coding: utf-8 -*-importcottonformationascffromcottonformation.resimportsecretsmanagerdefmake_tpl_1()->cf.Template:"""
    Create Secret1
    """tpl=cf.Template()secret1=secretsmanager.Secret("Secret1",p_Name="aws_cft_secret1",p_Description="This is Secret 1",p_Tags=[cf.Tag(p_Key="Creator",p_Value="Alice"),cf.Tag(p_Key="Description",p_Value="Hello"),])tpl.add(secret1)returntpldefmake_tpl_2()->cf.Template:"""
    Modify Secret1
    Create Secret222
    """tpl=make_tpl_1()secret1:secretsmanager.Secret=tpl.Resources["Secret1"]secret1.p_Description="This must be Secret 1"secret1.p_Tags=[cf.Tag(p_Key="Creator",p_Value="Bob"),cf.Tag(p_Key="Env",p_Value="Dev"),]secret2=secretsmanager.Secret("Secret222",p_Name="aws_cft_secret2",p_Description="This is Secret 2",)tpl.add(secret2)output_secret2_arn=cf.Output("Secret222Arn",Value=secret2.ref(),)tpl.add(output_secret2_arn)returntpldefmake_tpl_3()->cf.Template:"""
    Delete Secret1
    Modify Secret222
    Create Secret33333
    """tpl=make_tpl_2()tpl.remove(tpl.Resources["Secret1"])secret2:secretsmanager.Secret=tpl.Resources["Secret222"]secret2.p_Description="This definitely be Secret 2"secret2.p_Tags=[cf.Tag(p_Key="Creator",p_Value="Cathy"),cf.Tag(p_Key="Env",p_Value="QA"),]secret2.ra_Metadata={"email":"cathy@email.com"}secret3=secretsmanager.Secret("Secret33333",p_Name="aws_cft_secret3",p_Description="This is Secret 3",)tpl.add(secret3)returntpl⭐Deployment Script:# -*- coding: utf-8 -*-fromaws_cloudformation.apiimportdeploy_stack,remove_stackfromaws_cloudformation.testsimportbsmfromaws_cloudformation.tests.stacks.secretmanager_stackimport(make_tpl_1,make_tpl_2,make_tpl_3,)stack_name="cottonformation-deploy-stack-test"deploy_stack(bsm,stack_name=stack_name,template=make_tpl_1().to_json(),skip_prompt=True,# by default, it prompt user input for YES / NO to proceed# skip_plan=False, # by default, it does plan first# wait=True, # by default, it waits the update to finish)deploy_stack(bsm,stack_name=stack_name,template=make_tpl_2().to_json(),skip_prompt=True,)deploy_stack(bsm,stack_name=stack_name,template=make_tpl_3().to_json(),skip_prompt=True,)remove_stack(bsm,stack_name=stack_name,skip_prompt=True,)Installaws_cloudformationis released on PyPI, so all you need is:$pipinstallaws_cloudformationTo upgrade to latest version:$pipinstall--upgradeaws_cloudformation