Best Python code snippet using localstack_python
tfnsw-jenkins.py
Source:tfnsw-jenkins.py
...34 )35 return response36 def get_stack_name_from_filename(self,filename):37 return filename.rsplit('.')[0]38 def get_template_summary(self,session, **args):39 client = session.client('cloudformation')40 response = client.get_template_summary(**args)41 return response42 def describe_stacks(self,session, **args):43 client = session.client('cloudformation')44 response = client.describe_stacks(**args)45 return response46 47 def get_template_body(self, session, **args):48 client = session.client('cloudformation')49 response = client.get_template(**args)50 return response['TemplateBody']51 def s3_upload(self,session, filename, bucket, key):52 s3 = session.resource('s3')53 s3.meta.client.upload_file(filename, bucket, key)54 def create_change_set(self,session,stackname,bucketname,parameters,changesetname,description):55 client = session.client('cloudformation')56 cf = boto3.client("cloudformation")57 response = client.create_change_set(58 StackName=stackname,59 TemplateURL="https://s3-ap-southeast-2.amazonaws.com/"+bucketname+"/"+stackname+".template",60 Parameters= parameters,61 Capabilities=[62 'CAPABILITY_IAM',63 'CAPABILITY_NAMED_IAM'64 ],65 ChangeSetName=changesetname,66 Description=description67 )68 # wait till task completes, waiter breaks when create_change_set failes69 try:70 waiter = cf.get_waiter('change_set_create_complete')71 waiter.wait(StackName=stackname,ChangeSetName=changesetname)72 except botocore.exceptions.WaiterError:73 # possibly create_change_set failed74 pass75 return response 76 def describe_change_set(self,session,changesetname,stackname):77 client = session.client('cloudformation')78 response = client.describe_change_set(79 ChangeSetName=changesetname,80 StackName=stackname81 )82 try:83 print("waiting for CREATE_COMPLETE...")84 waiter = client.get_waiter('change_set_create_complete')85 waiter.wait(StackName=stackname,ChangeSetName=changesetname)86 response = client.describe_change_set(87 ChangeSetName=changesetname,88 StackName=stackname89 )90 return response91 except botocore.exceptions.WaiterError:92 return response93 def delete_change_set(self,session,changesetname,stackname):94 client = session.client('cloudformation')95 response = client.delete_change_set(96 ChangeSetName=changesetname,97 StackName=stackname98 )99 return response100 def execute_change_set(self,session,changesetname,stackname):101 client = session.client('cloudformation')102 response = client.execute_change_set(103 ChangeSetName=changesetname,104 StackName=stackname105 )106 return response107# --end of class--108def stack_exist(stackname):109 try:110 stack = dcf.describe_stacks(session,StackName=stackname)111 return True112 except:113 return False114def get_stack_parameters(stackname):115 section = list()116 try:117 stack = dcf.describe_stacks(session,StackName=stackname)118 section = stack['Stacks'][0]['Parameters']119 return sorted(section, key=itemgetter('ParameterKey'), reverse=False)120 except:121 return section 122def get_stack_outputs(stackname):123 section = list()124 try:125 stack = dcf.describe_stacks(session,StackName=stackname)126 section = stack['Stacks'][0]['Outputs']127 return section 128 except:129 return section 130def get_template_parameters(templatename):131 TemplateBody = open(templatename).read()132 summary = dcf.get_template_summary(session, TemplateBody=TemplateBody)133 LocalParameters = list() 134 for item in summary['Parameters']:135 try:136 LocalParameters.append(137 {138 "ParameterKey": item['ParameterKey'], 139 "ParameterValue": item['DefaultValue']140 }141 )142 except KeyError:143 # Default not set144 LocalParameters.append(145 {146 "ParameterKey": item['ParameterKey'], ...
capabilities.py
Source:capabilities.py
1def get(template_url, session):2 """Gets the needed capabilities for the CloudFormation stack """3 cfn_client = session.client('cloudformation')4 template_details = cfn_client.get_template_summary(5 TemplateURL=template_url)6 try:7 stack_capabilities = template_details['Capabilities']8 except KeyError:9 # May not be needed since it's not required when creating or updating a10 # stack11 stack_capabilities = []...
cloudformation.py
Source:cloudformation.py
1import boto32CFN = boto3.client('cloudformation')3def list_parameters(url):4 summary = CFN.get_template_summary(5 TemplateURL=url6 )7 if 'Parameters' in summary:8 return summary['Parameters']...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!