I am new to aws lambda. I am trying to send mail with aws ses with aws lambda, without any triggers. Here is my code
import boto3
from botocore.exceptions import ClientError
ses = boto3.client('ses')
email_from = '[email protected]'
email_to = '[email protected]'
emaiL_subject = 'Subject'
email_body = 'Body'
def lambda_handler(event, context):
response = ses.send_email(
Source = email_from,
Destination={
'ToAddresses': [
email_to,
],
},
Message={
'Subject': {
'Data': emaiL_subject
},
'Body': {
'Text': {
'Data': email_body
}
}
}
)
I've created a custome role with simple microservices permission. The event is set to hello world. I saved and clicked on test, it shows this errors
{
"errorMessage": "An error occurred (AccessDenied) when calling the SendEmail operation: User `arn:aws:sts::990458801115:assumed-role/basic-lambda-role/sendmail' is not authorized to perform `ses:SendEmail' on resource `arn:aws:ses:us-east-1:990458801115:identity/[email protected]'",
"errorType": "ClientError",
"stackTrace": [
[
"/var/task/lambda_function.py",
28,
"lambda_handler",
"'Data': email_body"
],
[
"/var/runtime/botocore/client.py",
314,
"_api_call",
"return self._make_api_call(operation_name, kwargs)"
],
[
"/var/runtime/botocore/client.py",
612,
"_make_api_call",
"raise error_class(parsed_response, operation_name)"
]
]
}
I wrote the code from here, it runs perfectly locally.
The identity provider(s) lambda.amazonaws.com
– John Hanley