AWS SES pass data between lambda actions - amazon-web-services

i have setup 2 Lambda actions, within and SES Ruleset and i'm looking for a way to pass data between the 2 lambda.
Scenario :
User sends an email to example.com
SES triggers the first Lambda action in the ruleset on receiving the email
SES triggers the second Lambda action in the ruleset, with the returned data from the first action
is this possible, or is there another best practice to do so ?
Thank you

That is the reason AWS created a service called Step Functions.
You can make a parallel or sequential call between lambda's and pass data between them.
Checkout the documentation Step Functions Getting Started

Related

How to send email after a new DynamoDB entry without Lambda function

I would normally handle the task of sending an email after a new DynamoDB entry with Lambda and SES but I'm required to not use Lambda for it.
There's a 'Contact us' section in the website and the email needs to be sent every time a new entry is made. We use API Gateway to post the data to DyanmoDB
Is there a way to carry this out without Lambda?
It's not possible without writing code. Furthermore you may probably want to tailor each email to make it more personal to the user, thus Lambda is a must.
You could design something using EventBridge Pipes which can trigger when a new user is added and can have SNS as a destination which could trigger an email. But that email may not be customizable nor may it send to people not subscribed to the topic
DynamoDB triggers Lambda functions by feeding the records of a DynamoDB Stream to the Lambda function. That is by far the easiest way to process updates to a DynamoDB table, but you can also write other code that processes a DynamoDB outside of Lambda: https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Streams.html
If you really want to do it without lambda you can use the following pattern and glue some AWS services together.
You can consume the dynamodb stream with eventbridge pipes and send it to a stepfunction and there you use the sdk integration to call SES. Instead of stepfunction you can directly use SNS for simpler setups.
You will not have to use lambda for this setup. Further you can transform your message either in the pipe or in the stepfunction.
Be aware that eventbirdge pipes has currently no AWS CDK L2 construct which might make it harder to configure if you use CDK.

Invoke AWS lambda function from slack channel using AWS Chatbot - automate it, without user intervention

I've a slack workflow setup which will take approval in different channel and invoke AWS lambda from another private channel to restrict the access to AWS chatbot. But after the lambda is invoked, Chatbot is again asking for confirmation which requires some one to manually approve it again. Is there any way to bypass this.?
The aim is to automate this and remove user intervention, any workaround is appreciated
The documentation of AWS Bot states that :
https://aws.amazon.com/blogs/devops/running-aws-commands-from-slack-using-aws-chatbot/
Invoke a Lambda function from Slack To trigger a workflow or a runbook
from Slack, you can invoke a Lambda function by running #aws lambda
invoke FUNCTION_NAME. AWS Chatbot will ask for a confirmation.

How to call an API Gateway API once a week

I have a REST API built using API Gateway with a couple of methods. I need to run a POST request on a method /generate-stats once a week. I currently call this method through the AWS console by pasting a request body into the "Test" feature that exists in API Gateway under the Method Execution flowchart.
How would I go about automating this call? Would a lambda that runs once a week be the simplest solution? Ideally I can store the response or trigger an alarm if the request fails.
If you want to automate a request to happen once a week you would want to look at using Amazon EventBridge.
The service itself supports either being triggered by an event (such as a new PutObject into S3 or an instance being launched) or can run based on a schedule. You would want to use the latter to set a cron expression for running this.
The next part of the rule is the target which in this case are a couple of approaches.
API Gateway requests are a supported target from within the event. If the supported functionality with EventBridge is suitable for you then you will be able to perform the request directly without any additional services.
If additional functionality is required you would need to create a Lambda function that could perform the request to API Gateway. This Lambda would then be the trigger for the event leading to the same functionality being performed.
You can build a Lambda function that can use code to perform a POST request. Then you can use scheduled events to schedule when the Lambda function will be invoked. Using a CRON expression, you can schedule your Lambda to fire once a week. For details, see:
Schedule AWS Lambda Functions Using CloudWatch Events

Best way to trigger events from incoming SES email

I want to trigger some events based on the body of incoming emails. I see at least two ways of doing this with SES and Lambda, and I'm wondering about the pros and cons.
SES triggers Lambda function. Since SES is only available in a few regions, this means the Lambda function must also be in one of those regions. This passes a JSON object to Lambda containing the headers but not the email content.
SES publishes to SNS, and Lambda function subscribes to the SNS topic. The SNS topic must be in the same region as SES, but the Lambda function can be anywhere. This way the Lambda function receives the full email content, up to maximum size of 150KB.
SES puts the message into S3 bucket, then S3 triggers Lambda. Bucket must be in the same region. This seems overly complex and might take longer because there is an extra call to get the S3 object. There is some potential for error if another user puts objects into the same bucket. This way you can use emails up to 10MB.
Are there any other options or have I gotten anything wrong?
I have gone the SES -> S3 bucket route. I have an S3 event that fires a lambda on create. The lambda then reads the email and moves it to another bucket with a ${emailAddress}/${emailSubject} format as the key and then deletes the original. This allows me to programmatically pull the body based on the email address and subject combination (which is known) in some of my automated tests. Usually, this occurs well within a second. (Today it seems to be running really slow... searching to figure out why which lead me here)

Web email form that makes use of AWS API Gateway & Lambda

I created an email form on my website that calls an API Gateway endpoint as my HTML form action. It delivers the payload (a few lines of text generally) to the endpoint which triggers my AWS Lambda func. This works as planned, but it's a little slow (2-5 seconds) as sending email via SES takes a few seconds.
I'd like to use an in-memory datastore like Redis or Memcached to just set the data and close the Lambda func., but this seems expensive for my limited use case - I get 10-15 emails per month.
Is a better use case delivering the payload to an API Gateway endpoint - same as before - but have the AWS Lambda func. save the data immediately to an AWS DynamoDb instance which then closes the connection (terminates the AWS Lambda func.) ... and behind the scenes a second AWS Lambda func. would invoke/trigger that would then deliver the email to the appropriate account?
The delay I'm having appears to be the actual sending of the email using AWS SES so I'm trying to make this faster. I can do the above or is there a better way to invoke an SES instance to send email ... maybe async. somehow?
The usual pattern for this sort of thing is to push the data into a queue and have a second lambda consume it (to actually send the email). For this volume, the free tier should be plenty :)