bk_in = os.environ.get('BUCKET_IN', 'sk-pollybucket-in') myapi_name = os.environ.get('API_NAME', 'ServerLessPollyAPI') stage_name = os.environ.get('STAGE_NAME', 'development') region = os.environ.get('REGION', 'us-east-1') folder='./site_files/' template = folder + '_scripts.js' outfile = folder + 'scripts.js' s3 = boto3.client("s3") bucket_name = bk_in object_list = ['scripts.js', 'styles.css', 'index.html'] # Add the API end point to the _scripts.js file to generate scripts.js # var API_ENDPOINT = "https://{api-id}.execute-api.{us-east-1}.amazonaws.com/{stagename}" url = myutils.get_api_invoke_url(myapi_name, stage_name) api_id = myutils.get_api_ids(myapi_name)['api_id'] add_str = f'var API_ENDPOINT = "https://{api_id}.execute-api.{region}.amazonaws.com/{stage_name}"' print ("Generating scripts.js file with API ENDPOINT " + '\n' + add_str) try: with open(template, 'r+') as f: template_content = f.read() try: with open(outfile, 'w') as out: out.seek(0, 0) out.write(add_str + '\n' + template_content) except (IOError): print ("Could not write to file" + outfile) except (IOError): print("Could not open template file" + template)
#!/usr/bin/python3 import boto3 import json import sys import os sys.path.append('../../lib') import myutils myapi_name = os.environ.get('API_NAME', 'ServerLessPollyAPI') ids = myutils.get_api_ids(myapi_name) myapi_id = ids['api_id'] root_id = ids['root_id'] resource_id = ids['resource_id'] apigw = boto3.client('apigateway') print("--------------------API---------------------------------------") response = apigw.get_rest_api(restApiId=myapi_id) print(json.dumps(response, indent=4, sort_keys=True, default=str)) print("-------------------------GET----------------------------------") response = apigw.get_method(restApiId=myapi_id, resourceId=resource_id, httpMethod='GET') print(json.dumps(response, indent=4, sort_keys=True, default=str)) print("-----------------------POST------------------------------------") response = apigw.get_method(restApiId=myapi_id, resourceId=resource_id, httpMethod='POST') print(json.dumps(response, indent=4, sort_keys=True, default=str))