0

I want to send an email from AWS lambda using AWS pinpoint to the end-user using Python.

  • This link: https://docs.aws.amazon.com/pinpoint/latest/developerguide/send-messages-sdk.html should help you. Boto3 library should be included in lambda execution environment – MiHu Nov 26 '20 at 10:20
  • I have followed the above link and execute the program, but I am not able to send an email. I am not getting any error , but in response, I get null. – Minhaj Khan Nov 27 '20 at 05:48
  • The above is URL is working fine – Minhaj Khan Nov 30 '20 at 05:25
  • How To use a PinPoint template which I have created, how to use pinpoint template in aws lambda – Minhaj Khan Dec 07 '20 at 10:44

1 Answers1

2

I was able to get the example from https://docs.aws.amazon.com/pinpoint/latest/developerguide/send-messages-sdk.html to work with just a couple updates to the code.

  1. Deploy a new pinpoint project. Go to Settings > General Settings and note the Project ID.
  2. Pinpoint should prompt you to verify your email address since you're in the sandbox, put in your email and click the appropriate link that is emailed to you.
  3. Create a new blank lambda and add the following permissions policy to the role in IAM:
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "Pinpoint",
            "Effect": "Allow",
            "Action": "mobiletargeting:SendMessages",
            "Resource": "*"
        }
    ]
}
  1. Add the code from the developer guide to your lambda. Move the import statement above the lambda handler, and the rest inside the lambda handler. Like this:
    import boto3

    from botocore.exceptions import ClientError
    
    def lambda_handler(event, context):
    
        # The AWS Region that you want to use to send the email. For a list of
        # AWS Regions where the Amazon Pinpoint API is available, see
        # https://docs.aws.amazon.com/pinpoint/latest/apireference/
        AWS_REGION = "us-east-1"
        
        # The "From" address. This address has to be verified in
        # Amazon Pinpoint in the region you're using to send email.
        [...]
  1. Then update the following items from the sample:
AWS_REGION = [the region you setup your pinpoint and lambda]
SENDER = [your verified email address]
TOADDRESS = [your verified email address]
APPID = [your project id from pinpoint]
  1. Run the lambda and you should receive the email.
Coin Graham
  • 1,343
  • 3
  • 11