Skip to content

Commit

Permalink
update state machine
Browse files Browse the repository at this point in the history
  • Loading branch information
joelbalcaen committed May 2, 2024
1 parent 6c5875b commit f0c5453
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 24 deletions.
5 changes: 2 additions & 3 deletions lambdas/email_sender/src/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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)

Expand Down
14 changes: 14 additions & 0 deletions lambdas/text_replacer/event.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
13 changes: 0 additions & 13 deletions lambdas/text_replacer/lambda.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
24 changes: 16 additions & 8 deletions state_machines/rfp_email_form_fill/state_machine.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,23 @@
"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"
},
"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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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": "<h1>test</h1>"
}
]
}
},
"Retry": [
Expand Down

0 comments on commit f0c5453

Please sign in to comment.