From f0c545354ce7f9b4eea5e51eea22814e3fe8db04 Mon Sep 17 00:00:00 2001 From: Joel Balcaen Date: Thu, 2 May 2024 10:29:57 -0300 Subject: [PATCH] update state machine --- lambdas/email_sender/src/index.py | 5 ++-- lambdas/text_replacer/event.json | 14 +++++++++++ lambdas/text_replacer/lambda.tf | 13 ---------- .../rfp_email_form_fill/state_machine.json | 24 ++++++++++++------- 4 files changed, 32 insertions(+), 24 deletions(-) create mode 100644 lambdas/text_replacer/event.json diff --git a/lambdas/email_sender/src/index.py b/lambdas/email_sender/src/index.py index 206cffe..cf27237 100644 --- a/lambdas/email_sender/src/index.py +++ b/lambdas/email_sender/src/index.py @@ -15,7 +15,7 @@ def lambda_handler(event, context): destination_email = event['destination_email'] subject = event['subject'] body = event['body'] - attachment_s3_arns = event['attachment_s3_arns'] + attachment_s3_arns = event.get('attachment_s3_arns', []) ses = boto3.client('ses') s3 = boto3.client('s3') @@ -25,8 +25,7 @@ def lambda_handler(event, context): msg['From'] = sender_email msg['To'] = destination_email - for mime_text_json in body: - mime_text_dict = json.loads(mime_text_json) + for mime_text_dict in body: mime_text = MIMEText(mime_text_dict['message'], mime_text_dict['type']) msg.attach(mime_text) diff --git a/lambdas/text_replacer/event.json b/lambdas/text_replacer/event.json new file mode 100644 index 0000000..a351b9c --- /dev/null +++ b/lambdas/text_replacer/event.json @@ -0,0 +1,14 @@ +{ + "doc_s3_arn": "arn:aws:s3:::mybucket/some_path/myhtml.html", + "replacements": [ + {}, + { + "replacement_key": "title", + "replacement_value": "My New Title" + }, + { + "replacement_key": "h1", + "replacement_value": "My New H1" + } + ] +} \ No newline at end of file diff --git a/lambdas/text_replacer/lambda.tf b/lambdas/text_replacer/lambda.tf index b432514..0608cb8 100644 --- a/lambdas/text_replacer/lambda.tf +++ b/lambdas/text_replacer/lambda.tf @@ -22,19 +22,6 @@ module "lambda_function_container_image" { attach_policy_statements = true source_path = "${path.module}/src" - # see https://github.com/terraform-aws-modules/terraform-aws-lambda/issues/346 on why this custom path is necessary - # source_path = [ - # { - # path = "${path.module}/src" - # commands = [ - # ":zip", - # "cd `mktemp -d`", - # "python3 -m pip install --no-compile --only-binary=:all: --platform=manylinux2014_x86_64 --target=. -r ${abspath(path.module)}/src/requirements.txt", - # ":zip .", - # ] - # } - # ] - policy_statements = { log_group = { effect = "Allow" diff --git a/state_machines/rfp_email_form_fill/state_machine.json b/state_machines/rfp_email_form_fill/state_machine.json index 6efb3f4..8108d5b 100644 --- a/state_machines/rfp_email_form_fill/state_machine.json +++ b/state_machines/rfp_email_form_fill/state_machine.json @@ -14,7 +14,7 @@ "email_id.$": "$.Records[0].ses.mail.messageId", "raw_email_key.$": "States.Format('rfp/raw_emails/{}', $.Records[0].ses.mail.messageId)", "sender_email.$": "$.Records[0].ses.mail.source", - "form_to_fill_s3_uri.$": "States.Format('s3://levio-demo-fev-esta-ses-bucket-dev/rfp/executions/{}_{}/rfp.docx', $$.State.EnteredTime, $.Records[0].ses.mail.messageId)" + "form_to_fill_s3_uri.$": "States.Format('s3://levio-demo-fev-esta-ses-bucket-dev/rfp/executions/{}_{}/formulaire.html', $$.State.EnteredTime, $.Records[0].ses.mail.messageId)" } }, "Type": "Pass" @@ -22,15 +22,15 @@ "Parallel": { "Branches": [ { - "StartAt": "Create copy of the RFP Form doc", + "StartAt": "Create copy of the RFP HTML form", "States": { - "Create copy of the RFP Form doc": { + "Create copy of the RFP HTML form": { "Comment": "Copy the form to be filled into this execution's email folder", "End": true, "Parameters": { "Bucket.$": "$.execution_metadata.bucket", - "CopySource.$": "States.Format('{}/rfp/configuration/rfp.docx', $.execution_metadata.bucket)", - "Key.$": "States.Format('{}/rfp.docx', $.execution_metadata.work_folder)" + "CopySource.$": "States.Format('{}/rfp/configuration/formulaire.html', $.execution_metadata.bucket)", + "Key.$": "States.Format('{}/formulaire.html', $.execution_metadata.work_folder)" }, "Resource": "arn:aws:states:::aws-sdk:s3:copyObject", "Type": "Task" @@ -160,7 +160,7 @@ "Type": "Task", "Resource": "arn:aws:states:::lambda:invoke", "Parameters": { - "FunctionName": "arn:aws:lambda:us-east-1:446872271111:function:levio-esta-document-filler:$LATEST", + "FunctionName": "arn:aws:lambda:us-east-1:446872271111:function:levio-esta-text-replacer:$LATEST", "Payload": { "doc_s3_arn.$": "$.execution_metadata.form_to_fill_s3_uri", "replacements.$": "$.map_to_document_filler_args_output" @@ -192,8 +192,16 @@ "destination_email.$": "$.execution_metadata.sender_email", "sender_email.$": "$.execution_metadata.destination_email[0]", "subject": "", - "body": "Voici le formulaire rempli. Merci.", - "attachment_s3_arns.$": "States.Array($.execution_metadata.form_to_fill_s3_uri)" + "body": [ + { + "type": "plain", + "message": "Voici le formulaire rempli. Merci." + }, + { + "type": "html", + "message": "

test

" + } + ] } }, "Retry": [