python lambda 를 이용하여 SES 를 사용하는 코드 예제 입니다.


import json
import boto3
from botocore.exceptions import ClientError

sender = "no-reply@mycompany.com" # 보내는 사람 이메일 SES 에 시전에 등록되어 있어야 함

client = boto3.client('ses')

def lambda_handler(event, context):
    
    jd = json.dumps(event);
    jsonOBject = json.loads(jd)
    
    subject = jsonOBject['subject']
    body = jsonOBject['body']
    recipient = jsonOBject['to']
    try:
        response = client.send_email(
            Destination={
                'ToAddresses': recipient,
            },
            Message={
                'Body': {
                    'Text': {
                        'Data' : body
                    }
                },
                'Subject': {
                    'Data': subject
                }
            },
            Source=sender
        )
    except ClientError as e:
        print(e.response['Error']['Message'])
    else:
        print("Email send!, Message ID")
        print(response['MessageId'])
        return response

그리고 테스트 이벤트는 아래와 같이 작성합니다.


{
  "to": [
    "test1@mycompany.com", "test2@mycompany.com"
  ],
  "subject": "[py] 에서 보내는 테스트 메일 제목",
  "body": "[py] 에서 보내는 테스트 메일 내용"
}