Best Python code snippet using localstack_python
deployment_helper.py
Source:deployment_helper.py
...45 aws_access_key_id=self.aws_access_key_id,46 aws_secret_access_key = self.aws_secret_access_key,47 region_name=self.aws_region48 )49 def put_rest_api(self):50 """Reimport api swagger file to AWS api gateway51 """52 # Retrieve content of the api swagger template53 with open(self.api_json_file, 'rb') as fp:54 data = fp.read()55 print("Reimport API swagger file to api gateway [{}] ...".format(self.aws_restapiid))56 resp = self.client.put_rest_api(restApiId=self.aws_restapiid, mode='overwrite', body=data)57 print('Response:\n{}'.format(json.dumps(resp, cls=DefaultEncoder, indent=2)))58 return resp['ResponseMetadata']['HTTPStatusCode'] in HTTPS_OK_CODES59 def create_deployment(self, stage_name, bucket_name, cache_enabled, cache_size):60 """Create or update a deployment stage61 """62 print("Create or update deployment stage [{}] of api gateway [{}] ...".format(stage_name, self.aws_restapiid))63 resp = self.client.create_deployment(64 restApiId=self.aws_restapiid,65 stageName=stage_name,66 stageDescription=stage_name,67 description=stage_name, # TODO a proper description instead of using the stage name68 cacheClusterEnabled=bool(cache_enabled),69 cacheClusterSize=cache_size,70 variables={71 'bucket': bucket_name72 }73 )74 print('Response:\n{}'.format(json.dumps(resp, cls=DefaultEncoder, indent=2)))75 return resp['ResponseMetadata']['HTTPStatusCode'] in HTTPS_OK_CODES76def main():77 # Retrieve what action to be done from command line78 parser = argparse.ArgumentParser(79 description="Reimport the API Swagger template to AWS and run tests. "\80 + "If `deploy` is specified, the program will instead deploy the "\81 + "current rest api to the specified stage and tested."82 )83 parser.add_argument('--deploy', help="Deploy the current rest api to a stage. Choices: [test, stage, prod]")84 args = parser.parse_args(sys.argv[1:])85 # Retrieve AWS resource settings from the ini file86 config = configparser.ConfigParser()87 config.read(SETTINGS['ini_file'])88 SETTINGS['aws_restapiid'] = config['default']['aws.apigateway.restApiId']89 helper = ApiGatewayHelper(SETTINGS)90 if args.deploy is None:91 # Put the restapi to AWS92 if helper.put_rest_api() is False:93 logging.error("Failed to reimport the api swagger file. Aborted")94 return 195 else:96 # Retrieve stage-specific settings97 stage_name = args.deploy.lower()98 profile = stage_name if stage_name in config.sections() else 'test'99 s3 = config[profile]['aws.s3']100 cache_enabled = True if config[profile]['aws.apigateway.cacheClusterEnabled'].lower() == 'true' else False101 cache_size = config[profile]['aws.apigateway.cacheClusterSize']102 if helper.create_deployment(stage_name, s3, cache_enabled, cache_size) is False:103 logging.error("Failed to create deployment stage. Aborted")104 return 1105 return 0106if __name__ == '__main__':...
apigateway.py
Source:apigateway.py
...28 defs = {k: v for k, v in getattr(xargs, 'def') or []}29 data = load(xargs.template)30 data = template.render(data, defs=defs)31 dump(data, xargs.swagger)32def put_rest_api(args=None):33 """34 import swagger to Gateway API35 :param args:36 :return:37 """38 xargs = parse_arguments('aws.apigateway.put-rest-api', args=args)39 print("Importing Swagger to API Gateway: %s" % (xargs.swagger,))40 # read file41 with open(xargs.swagger) as f:42 body = f.read()43 # put rest api definition44 AWSSession().client('apigateway').put_rest_api(45 restApiId=xargs.rest_api_id,46 mode='overwrite',47 failOnWarnings=True,48 body=body...
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!!