Running AWS SES Lambda function locally with Docker

Question:

I’m a newbie to docker and lambda functions and I’m trying to run a simple lambda function locally (sample code below) to send emails using the AWS Simple Email Service. I’ve got limited access to an AWS Sandbox account which means I don’t have AWS Access Keys to test this on the AWS account or connect locally. Also, my assigned role on the AWS Sandbox account doesn’t have an attached policy for SES.

Can I test this function locally using just AWS SAM and Docker? And if I can, do I have to build all the parameters that will simulate a local AWS environment in my local SAM project or I can build a container from an already existing Docker Image. I’ve tried a couple of Docker images such as this that allows for local testing, but I’m not sure how to go about it.

import json
import boto3


def lambda_handler(event, context):

    ses = boto3.client('ses')
    body = message_body

    ses.send_email(Source='From_Address',
               Destination={'ToAddresses': ['To_Address']},
               Message={'Subject': {'Data': 'Test Message',
               'Charset': 'UTF-8'}, 'Body': {'Text': {'Data': body,
               'Charset': 'UTF-8'}}})


    return {'statusCode': 200,
        'body': json.dumps('Message successfully sent')}
Asked By: TheSoldier

||

Answers:

The solution I was looking for was a platform like LocalStack, which is a cloud service emulator that I can run in a container on your Mac/PC.

Answered By: TheSoldier