I am implementing automatic email sending using SES AWS Client V3 and Serverless framework. The serverless config yaml contains the required permissions:
iamRoleStatements:
- Effect: "Allow"
Action:
- "ses:*"
Resource:
- "*"
the code itself is straight forward:
const command = new SendTemplatedEmailCommand({
Source: EmailService.SOURCE_ADDRESS,
Template: templateName,
Destination: {
ToAddresses: emails
},
TemplateData: JSON.stringify(templateParams || {})
})
console.log(`Calling SES API Command...`);
const response = await this._ses.send(command);
the await call never returns and the backing lambda function is timing out after 20 seconds. There are not errors appearing in the cloudwatch lambda function log. The maximum timeout of a lambda function is 30 seconds and the timeout of SES Client V3 is not configurable so I cannot "let it timeout" before the lambda itself times out... Important note: when running locally (using serverless offline plugin) using the same credentials for AWS, the call completes successfully and the mail is sent. Another note: the same lambda is also using AWS SDK S3 client V3 - without any trouble - so I assume that SDK setup is not the issue here... Any ideas?
The reason for the timeout is that the lambda function was inside a VPC and therefore could not reach the public SES API. A rookie mistake...