in lambda_call_lambda_to_run_redshift_script.py [0:0]
def handler(event, context):
print(event)
if event['RequestType'] == 'Delete':
cfnresponse.send(event, context, cfnresponse.SUCCESS, {'Data': 'No Action Needed'})
# Check if this is a Create and we're failing Creates
elif event['RequestType'] == 'Create' and event['ResourceProperties'].get('FailCreate', False):
raise RuntimeError('Create failure requested')
else:
action = event['ResourceProperties']['Action']
redshift_host = event['ResourceProperties']['RedshiftHost']
redshift_db = event['ResourceProperties']['RedshiftDb']
redshift_user = event['ResourceProperties']['RedshiftUser']
script_s3_path = event['ResourceProperties']['ScriptS3Path']
redshift_iam_role = event['ResourceProperties']['RedshiftIamRole']
lambda_arn = event['ResourceProperties']['LambdaArn']
lambda_payload = {
"input": {
"Action": action,
"RedshiftHost": redshift_host,
"RedshiftDb": redshift_db,
"RedshiftUser": redshift_user,
"RedshiftIamRole": redshift_iam_role,
"ScriptS3Path": script_s3_path,
"redshift_iam_role": redshift_iam_role
}
}
response = boto3.client('lambda').invoke(
FunctionName=lambda_arn,
InvocationType='Event',
Payload=json.dumps(lambda_payload)
)
print(response)
cfnresponse.send(event, context, cfnresponse.SUCCESS, {'Data': 'Create complete'})