def handler(event, context):
    '\n    Boto3 Proxy API Handler\n    '
    headers = event.get('Headers', event.get('headers'))
    if ('request-context-id' in headers):
        logger.set_uuid(headers['request-context-id'])
    logger.info({'Incoming event': event})
    logger.info('Incoming context: %s', context)
    request_body = json.loads(event.get('body', {}))
    try:
        secrets_client = boto3.client('secretsmanager')
        lambda_auth.authorize_lambda_request(event, MSFT_IDP_TENANT_ID, MSFT_IDP_APP_ID, MSFT_IDP_CLIENT_ROLES, LDAP_SERVER, LDAP_USERNAME, secrets.retrieve_ldap_password(secrets_client, logger, LDAP_PASSWORD_SECRET_NAME), LDAP_SEARCH_BASE, LDAP_OBJECT_CLASS, LDAP_GROUP_NAME, LDAP_LOOKUP_ATTRIBUTE)
        ssm_client = boto3.client('ssm')
    except Exception as e:
        traceback.print_exc()
        return {'statusCode': UNAUTHORIZED_STATUS, 'body': json.dumps({'error': f'Unauthorized. {str(e)}'})}
    resp_headers = {'Content-Type': 'application/json', 'request-context-id': logger.get_uuid()}
    if hasattr(context, 'local_test'):
        logger.info('Running at local')
    path_params = event.get('pathParameters', {})
    request_headers = event.get('headers', {})
    vpcxiam_endpoint = os.environ.get('vpcxiam_endpoint')
    vpcxiam_scope = os.environ.get('vpcxiam_scope')
    vpcxiam_host = os.environ.get('vpcxiam_host')
    resp = {'message': 'API action has been successfully completed'}
    status_code = SUCCESS_STATUS
    try:
        account = path_params.get('account-id')
        region = path_params.get('region-name')
        service = path_params.get('boto3-service')
        action = path_params.get('boto3-action')
        logger.info(f'Account: {account}')
        logger.info(f'Region: {region}')
        logger.info(f'Boto3 Service: {service}')
        logger.info(f'Boto3 Action: {action}')
        logger.info(f'is_authorized({request_headers}, {MSFT_IDP_APP_ID}, {MSFT_IDP_TENANT_ID}, {MSFT_IDP_CLIENT_ROLES}')
        url = (vpcxiam_endpoint + f'/v1/accounts/{account}/roles/admin/credentials')
        scope = vpcxiam_scope
        additional_headers = {'Host': vpcxiam_host}
        api_requests = api_request.ApiRequests()
        credentials = json.loads(api_requests.request(url=url, method='get', scope=scope, additional_headers=additional_headers).text)
        error = credentials.get('error', {})
        if error:
            logger.error(error)
            raise ValueError(error)
        credentials = credentials.get('credentials', {})
        try:
            ssm_parameter_name = ('/vpcx/aws/boto3-proxy/allowed-actions/' + service)
            logger.info(('Looking up parameter ' + ssm_parameter_name))
            allowed_actions = ssm_client.get_parameter(Name=ssm_parameter_name)
        except botocore.exceptions.ClientError as err:
            logger.error(err)
            if (err.response['Error']['Code'] == 'ParameterNotFound'):
                raise InvalidInputException((('Service ' + service) + ' is not an allowed service for the API'))
            else:
                raise error
        if (action not in allowed_actions['Parameter']['Value']):
            raise InvalidInputException((('Action ' + action) + ' is not an allowed action for the API'))
        ec2_client = boto3.client(service_name='ec2', aws_access_key_id=credentials.get('AccessKeyId', ''), aws_secret_access_key=credentials.get('SecretAccessKey', ''), aws_session_token=credentials.get('SessionToken', ''))
        helpers.is_region_valid(ec2_client, region)
        logger.info(f'{region} is a valid region')
        boto3_client = boto3.client(service_name=service, region_name=region, aws_access_key_id=credentials.get('AccessKeyId', ''), aws_secret_access_key=credentials.get('SecretAccessKey', ''), aws_session_token=credentials.get('SessionToken', ''))
        kwargs = request_body
        getattr(boto3_client, action)(**kwargs)
    except botocore.exceptions.ClientError as err:
        status_code = INTERNAL_SERVICE_ERROR_STATUS
        resp = {'error': f'{type(err).__name__}: {err}'}
    except InvalidRegionException:
        status_code = NOT_FOUND_STATUS
        resp = {'error': 'Please enter a valid region in the url path'}
    except InvalidInputException as err:
        status_code = BAD_REQUEST_STATUS
        resp = {'error': str(err)}
    except ValueError as err:
        status_code = NOT_FOUND_STATUS
        resp = {'error': str(err)}
    except Exception as err:
        status_code = INTERNAL_SERVICE_ERROR_STATUS
        resp = {'error': f'{type(err).__name__}: {err}'}
    resp = helpers.lambda_returns(status_code, resp_headers, json.dumps(resp))
    logger.info(f'response: {resp}')
    return resp
Boto3 Proxy API Handler
def handler(event, context):
    '\n    \n    '
    headers = event.get('Headers', event.get('headers'))
    if ('request-context-id' in headers):
        logger.set_uuid(headers['request-context-id'])
    logger.info({'Incoming event': event})
    logger.info('Incoming context: %s', context)
    request_body = json.loads(event.get('body', {}))
    try:
        secrets_client = boto3.client('secretsmanager')
        lambda_auth.authorize_lambda_request(event, MSFT_IDP_TENANT_ID, MSFT_IDP_APP_ID, MSFT_IDP_CLIENT_ROLES, LDAP_SERVER, LDAP_USERNAME, secrets.retrieve_ldap_password(secrets_client, logger, LDAP_PASSWORD_SECRET_NAME), LDAP_SEARCH_BASE, LDAP_OBJECT_CLASS, LDAP_GROUP_NAME, LDAP_LOOKUP_ATTRIBUTE)
        ssm_client = boto3.client('ssm')
    except Exception as e:
        traceback.print_exc()
        return {'statusCode': UNAUTHORIZED_STATUS, 'body': json.dumps({'error': f'Unauthorized. {str(e)}'})}
    resp_headers = {'Content-Type': 'application/json', 'request-context-id': logger.get_uuid()}
    if hasattr(context, 'local_test'):
        logger.info('Running at local')
    path_params = event.get('pathParameters', {})
    request_headers = event.get('headers', {})
    vpcxiam_endpoint = os.environ.get('vpcxiam_endpoint')
    vpcxiam_scope = os.environ.get('vpcxiam_scope')
    vpcxiam_host = os.environ.get('vpcxiam_host')
    resp = {'message': 'API action has been successfully completed'}
    status_code = SUCCESS_STATUS
    try:
        account = path_params.get('account-id')
        region = path_params.get('region-name')
        service = path_params.get('boto3-service')
        action = path_params.get('boto3-action')
        logger.info(f'Account: {account}')
        logger.info(f'Region: {region}')
        logger.info(f'Boto3 Service: {service}')
        logger.info(f'Boto3 Action: {action}')
        logger.info(f'is_authorized({request_headers}, {MSFT_IDP_APP_ID}, {MSFT_IDP_TENANT_ID}, {MSFT_IDP_CLIENT_ROLES}')
        url = (vpcxiam_endpoint + f'/v1/accounts/{account}/roles/admin/credentials')
        scope = vpcxiam_scope
        additional_headers = {'Host': vpcxiam_host}
        api_requests = api_request.ApiRequests()
        credentials = json.loads(api_requests.request(url=url, method='get', scope=scope, additional_headers=additional_headers).text)
        error = credentials.get('error', {})
        if error:
            logger.error(error)
            raise ValueError(error)
        credentials = credentials.get('credentials', {})
        try:
            ssm_parameter_name = ('/vpcx/aws/boto3-proxy/allowed-actions/' + service)
            logger.info(('Looking up parameter ' + ssm_parameter_name))
            allowed_actions = ssm_client.get_parameter(Name=ssm_parameter_name)
        except botocore.exceptions.ClientError as err:
            logger.error(err)
            if (err.response['Error']['Code'] == 'ParameterNotFound'):
                raise InvalidInputException((('Service ' + service) + ' is not an allowed service for the API'))
            else:
                raise error
        if (action not in allowed_actions['Parameter']['Value']):
            raise InvalidInputException((('Action ' + action) + ' is not an allowed action for the API'))
        ec2_client = boto3.client(service_name='ec2', aws_access_key_id=credentials.get('AccessKeyId', ), aws_secret_access_key=credentials.get('SecretAccessKey', ), aws_session_token=credentials.get('SessionToken', ))
        helpers.is_region_valid(ec2_client, region)
        logger.info(f'{region} is a valid region')
        boto3_client = boto3.client(service_name=service, region_name=region, aws_access_key_id=credentials.get('AccessKeyId', ), aws_secret_access_key=credentials.get('SecretAccessKey', ), aws_session_token=credentials.get('SessionToken', ))
        kwargs = request_body
        getattr(boto3_client, action)(**kwargs)
    except botocore.exceptions.ClientError as err:
        status_code = INTERNAL_SERVICE_ERROR_STATUS
        resp = {'error': f'{type(err).__name__}: {err}'}
    except InvalidRegionException:
        status_code = NOT_FOUND_STATUS
        resp = {'error': 'Please enter a valid region in the url path'}
    except InvalidInputException as err:
        status_code = BAD_REQUEST_STATUS
        resp = {'error': str(err)}
    except ValueError as err:
        status_code = NOT_FOUND_STATUS
        resp = {'error': str(err)}
    except Exception as err:
        status_code = INTERNAL_SERVICE_ERROR_STATUS
        resp = {'error': f'{type(err).__name__}: {err}'}
    resp = helpers.lambda_returns(status_code, resp_headers, json.dumps(resp))
    logger.info(f'response: {resp}')
    return resp