How to use create_base_path_mapping method in localstack

Best Python code snippet using localstack_python

bootstrap.py

Source:bootstrap.py Github

copy

Full Screen

...69 restApiId=response['id'],70 stageName=stage_name)71 logging.info('API ID "%s" deployed to stage "%s"', response['id'], stage_name)72 return response['id']73def create_base_path_mapping(rest_api_id, api_base, stage_name):74 """Link a custom domain with an API Gateway object stage"""75 client = boto3.client('apigateway', region_name=args.aws_region)76 # Note: this will fail if a mapping already exists (bootstrapping is not idempotent).77 response = client.create_base_path_mapping(78 domainName=api_base,79 basePath='(none)',80 restApiId=rest_api_id,81 stage=stage_name82 )83 logging.info("Domain '%s' now pointed to '%s':'%s'", api_base, rest_api_id, stage_name)84 return response85def file_arg_to_string(filename):86 with open(filename, "r", encoding='utf-8') as fin:87 body = fin.read()88 return body89if __name__ == '__main__':90 logging.basicConfig(level=logging.INFO, format='[%(asctime)s] %(levelname)s %(message)s')91 parser = argparse.ArgumentParser()92 parser.add_argument("--aws-profile", required=True)93 parser.add_argument("--aws-region", default="us-east-1")94 parser.add_argument("--stage-name", default="bootstrap")95 parser.add_argument("--api-base-domain", required=True,96 help="The name of the API Gateway domain to be created.")97 parser.add_argument("--ssl-cert-name", required=True,98 help="The name of the SSL certificate to associate with the daomin.")99 parser.add_argument("--ssl-cert", required=True,100 help="The path to the file containing the SSL cert from the CA.")101 parser.add_argument("--ssl-pk", required=True,102 help="The Private Key created when generating the CSR for the SSL certificte.")103 parser.add_argument("--ssl-cert-chain", required=True,104 help="The certificate chain provided by the CA.")105 parser.add_argument("--route53-hosted-zone", required=True,106 help="The AWS ID of the the Route53 hosted zone used for managing gateway DNS.")107 args = parser.parse_args()108 # Configure the default session and prompt for MFA token109 if args.aws_profile:110 boto3.setup_default_session(profile_name=args.aws_profile)111 # read file arguments into string vars112 ssl_cert = file_arg_to_string(args.ssl_cert)113 ssl_pk = file_arg_to_string(args.ssl_pk)114 ssl_cert_chain = file_arg_to_string(args.ssl_cert_chain)115 # Phase 1, create the api gateway "custom domain" and associated DNS record.116 # Note:117 # It can take up to 40 minutes for creation to complate.118 # Deletion takes time in the background, re-use of names, even for apparently119 # deleted domains can be problematic.120 domain = get_domain(args.api_base_domain)121 if not domain:122 logging.info("Custom domain does not exist, creating")123 domain = create_apigw_custom_domain_name(args.api_base_domain, args.ssl_cert_name,124 ssl_cert, ssl_pk, ssl_cert_chain)125 logging.info("Upserting DNS for the custom domain.")126 create_route53_rs(args.route53_hosted_zone, args.api_base_domain, domain['distributionDomainName'])127 # Phase 2, create the api gateway and dummy base path mapping128 base_path = get_base_path(args.api_base_domain)129 if not base_path:130 # Create new dummy API Gateway object and deploy to a stage131 api_id = bootstrap_api(args.stage_name)132 # Link custom domain to stage (base path mapping)133 create_base_path_mapping(api_id, args.api_base_domain, args.stage_name)134 logging.info('Bootstrap successful.')135 else:136 api_id = base_path['restApiId']137 logging.info('Bootstrap not necessary.')...

Full Screen

Full Screen

switch_and_cleanup.py

Source:switch_and_cleanup.py Github

copy

Full Screen

...50 preview_stage_name = next(item.get("stage") for item in response.get("items"))51 if not prod_stage_name:52 prod_stage_name = preview_stage_name53 print(f"Mapping production to stage: {prod_stage_name}")54 prod_response = client.create_base_path_mapping(55 domainName=prod_domain_name,56 restApiId=api_gateway_id,57 stage=prod_stage_name,58 basePath="(none)" # for a blank basepath "(none)" value is required, refer to boto3 documentation59 )60 preview_response = prod_response61 else:62 delete_mapping(preview_domain_name)63 delete_mapping(prod_domain_name)64 print(f"Mapping preview to stage: {prod_stage_name}")65 preview_response = client.create_base_path_mapping(66 domainName=preview_domain_name,67 restApiId=api_gateway_id,68 stage=prod_stage_name,69 basePath="(none)" # for a blank basepath "(none)" value is required, refer to boto3 documentation70 )71 print(f"Mapping production to stage: {preview_stage_name}")72 prod_response = client.create_base_path_mapping(73 domainName=prod_domain_name,74 restApiId=api_gateway_id,75 stage=preview_stage_name,76 basePath="(none)" # for a blank basepath "(none)" value is required, refer to boto3 documentation77 )78 stages_with_mappings = [preview_response.get("stage"), prod_response.get("stage")]79 stages_with_mappings = set(stages_with_mappings)80 all_stages = [item.get("stageName") for item in client.get_stages(restApiId=api_gateway_id).get("item")]81 print(f"All available stages: {all_stages}")82 stage_to_delete = [item for item in all_stages if item not in stages_with_mappings]83 stage_to_delete = next(item for item in stage_to_delete) if len(stage_to_delete) > 0 else None84 if stage_to_delete:85 delete_stage(86 stage_name=stage_to_delete,...

Full Screen

Full Screen

configure_custom_api_domain.py

Source:configure_custom_api_domain.py Github

copy

Full Screen

...25except Exception as error:26 print(error)27# method to set the base path for the domain28try:29 response2 = base_path.create_base_path_mapping(30 domainName='api.2edusite.com',31 basePath='',32 restApiId='ez9pmaodek',33 stage=''34 )35 print(response2)36 37except Exception as error:...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful