Best Python code snippet using localstack_python
cloudformation_starter.py
Source:cloudformation_starter.py
...202 output.description = output_json.get('Description')203 return output204 parse_output_orig = parsing.parse_output205 parsing.parse_output = parse_output206 # Patch DynamoDB get_cfn_attribute(..) method in moto207 def DynamoDB_Table_get_cfn_attribute(self, attribute_name):208 try:209 return DynamoDB_Table_get_cfn_attribute_orig(self, attribute_name)210 except Exception:211 if attribute_name == 'Arn':212 return aws_stack.dynamodb_table_arn(table_name=self.name)213 raise214 DynamoDB_Table_get_cfn_attribute_orig = dynamodb_models.Table.get_cfn_attribute215 dynamodb_models.Table.get_cfn_attribute = DynamoDB_Table_get_cfn_attribute216 # Patch SQS get_cfn_attribute(..) method in moto217 def SQS_Queue_get_cfn_attribute(self, attribute_name):218 if attribute_name == 'Arn':219 return aws_stack.sqs_queue_arn(queue_name=self.name)220 return SQS_Queue_get_cfn_attribute_orig(self, attribute_name)221 SQS_Queue_get_cfn_attribute_orig = sqs_models.Queue.get_cfn_attribute222 sqs_models.Queue.get_cfn_attribute = SQS_Queue_get_cfn_attribute223 # Patch Lambda get_cfn_attribute(..) method in moto224 def Lambda_Function_get_cfn_attribute(self, attribute_name):225 try:226 if attribute_name == 'Arn':227 return self.function_arn228 return Lambda_Function_get_cfn_attribute_orig(self, attribute_name)229 except Exception:230 if attribute_name in ('Name', 'FunctionName'):231 return self.function_name232 raise233 Lambda_Function_get_cfn_attribute_orig = lambda_models.LambdaFunction.get_cfn_attribute234 lambda_models.LambdaFunction.get_cfn_attribute = Lambda_Function_get_cfn_attribute235 # Patch DynamoDB get_cfn_attribute(..) method in moto236 def DynamoDB_Table_get_cfn_attribute(self, attribute_name):237 try:238 if attribute_name == 'StreamArn':239 streams = aws_stack.connect_to_service('dynamodbstreams').list_streams(TableName=self.name)['Streams']240 return streams[0]['StreamArn'] if streams else None241 return DynamoDB_Table_get_cfn_attribute_orig(self, attribute_name)242 except Exception as e:243 LOG.warning('Unable to get attribute "%s" from resource %s: %s' % (attribute_name, type(self), e))244 raise245 DynamoDB_Table_get_cfn_attribute_orig = dynamodb_models.Table.get_cfn_attribute246 dynamodb_models.Table.get_cfn_attribute = DynamoDB_Table_get_cfn_attribute247 # Patch IAM get_cfn_attribute(..) method in moto248 def IAM_Role_get_cfn_attribute(self, attribute_name):249 try:250 return IAM_Role_get_cfn_attribute_orig(self, attribute_name)251 except Exception:252 if attribute_name == 'Arn':253 return aws_stack.role_arn(self.name)254 raise255 IAM_Role_get_cfn_attribute_orig = iam_models.Role.get_cfn_attribute256 iam_models.Role.get_cfn_attribute = IAM_Role_get_cfn_attribute257 # Patch LambdaFunction create_from_cloudformation_json(..) method in moto258 @classmethod259 def Lambda_create_from_cloudformation_json(cls, resource_name, cloudformation_json, region_name):260 resource_name = cloudformation_json.get('Properties', {}).get('FunctionName') or resource_name261 return Lambda_create_from_cloudformation_json_orig(resource_name, cloudformation_json, region_name)262 Lambda_create_from_cloudformation_json_orig = lambda_models.LambdaFunction.create_from_cloudformation_json263 lambda_models.LambdaFunction.create_from_cloudformation_json = Lambda_create_from_cloudformation_json264 # add CloudWatch types265 parsing.MODEL_MAP['AWS::ApiGateway::Deployment'] = apigw_models.Deployment266 parsing.MODEL_MAP['AWS::ApiGateway::Method'] = apigw_models.Method267 parsing.MODEL_MAP['AWS::ApiGateway::Resource'] = apigw_models.Resource268 parsing.MODEL_MAP['AWS::ApiGateway::RestApi'] = apigw_models.RestAPI269 parsing.MODEL_MAP['AWS::StepFunctions::StateMachine'] = sfn_models.StateMachine270 @classmethod271 def RestAPI_create_from_cloudformation_json(cls, resource_name, cloudformation_json, region_name):272 props = cloudformation_json['Properties']273 name = props['Name']274 region_name = props.get('Region') or DEFAULT_REGION275 description = props.get('Description') or ''276 id = props.get('Id') or short_uid()277 return apigw_models.RestAPI(id, region_name, name, description)278 def RestAPI_get_cfn_attribute(self, attribute_name):279 if attribute_name == 'Id':280 return self.id281 if attribute_name == 'Region':282 return self.region_name283 if attribute_name == 'Name':284 return self.name285 if attribute_name == 'Description':286 return self.description287 if attribute_name == 'RootResourceId':288 for id, resource in self.resources.items():289 if resource.parent_id is None:290 return resource.id291 return None292 raise UnformattedGetAttTemplateException()...
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!!