![]() Print ("Calling CREATE_STACK method to create: " + cfn_stack_name_ss) #- Call CloudFormation API to create the stack TemplateBody='', Print (key_ss + " - "+ parameters_data_ss)įetch_stack_parameters_ss.append() Print (key_ss + " - "+ parameters_data_ss + " (not sent as parameter)") ![]() Template_url_ss = parameters_data_ssĮlif key_ss = "StackName" or key_ss = "RegionId": Print ("Loading parameters from parameters file:") #- Check the status of the stack deletionĬheck_status(cfn_client_ss, cfn_stack_name_ss) Print ("Calling Delete Stack API for " + cfn_stack_name_ss)Ĭfn_client_ss.delete_stack(StackName=cfn_stack_name_ss) User_response = input ("Do you want to delete or update the stack") #- If the stack already exists then delete it first Print ("Stack " + cfn_stack_name_ss + " already exists.") Stack_list_ss = cfn_client_ss.describe_stacks() #- Check if this stack name already exists Print ("You are deploying stack: " + cfn_stack_name_ss) #- Store parameters from file into local variablesĬfn_stack_name_ss = parameters_data_ss Print ("Connecting to region: " + region_ss)Ĭfn_client_ss = boto3.client('cloudformation', region_ss, aws_access_key_id=access_key_ss, aws_secret_access_key=secret_key_ss) #- Connect to AWS region specified in parameters file Parameters_data_ss = json.loads(json_data_ss) Print ("Parameters file: " + param_file_ss) Print ("Parameters file: " + param_file_ss + " is invalid!") Print ("Updated status of stack " + stack_ss_val + ": " + status_cur_ss)ĭef main(access_key_ss, secret_key_ss, param_file_ss): Print ("Stack " + stack_ss_val + " no longer exists") Print ("\rWaiting for status update(" + str(ln_loop) + ").",) Print ("Current status of stack " + stack_ss_val + ": " + status_cur_ss) Stacks_ss = cfn_client_ss.describe_stacks(StackName=cfn_stack_name_ss) For Rimpal % ls CFNStackCreation.py Parameter.jsonĭef check_status( cfn_client_ss, cfn_stack_name_ss ): Keep these two files in the same directory path from where you are going to execute the Python script. You need two files for automate creation of CloudFormation stack.ĬFNStackCreation.py -> Your Python Script Get hold of the AWS SDK for Python and installed it on the box where you are going to execute the Python Script. I have upgraded it to the latest Blog-Contents % Python -version In case of Mac it comes with default installed Python. Make sure you have the latest Python installed on your box where you are intending to run the Python Script. I would suggest to test the below scripts with small stack first and further you can customise the Python script for your own requirements.įollow the steps below to automate the Cloudformation stack creation. Here I am assuming that you know the basic Python and have understanding of the AWS SDK for Python. In this section of my blog, I am going to introduce how to use an AWS SDK for Python to automate the CloudFormation Stack creation. ![]() We can also automate the creation of the CloudFormation stack using AWS CLI, CodePipeline etc. CloudFormation stack can be created from AWS Console, AWS CLI or using many other ways.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |