Order of DynamoDB initialization impacts Amazon SES
<p>When sending mails through SES service I am running into the following error message spewed out by SES's sendEmail method.</p>

<pre><code>{ [XMLParserError: Non-whitespace before first tag.
Line: 0
Column: 1
Char: {]
  message: 'Non-whitespace before first tag.\nLine: 0\nColumn: 1\nChar: {',
  code: 'XMLParserError',
  retryable: true,
  time: Thu Sep 29 2016 15:34:20 GMT-0400 (Eastern Daylight Time),
  statusCode: 500 }
</code></pre>

<p>After quite a bit of debugging I have narrowed down that the problem is related the order of initialization of DynamoDB and SES objects. The following test code reproduces the problem:</p>

<pre><code>'use strict';

var AWS = require('aws-sdk');
AWS.config.update({region:'us-east-1'});

//var ses = new AWS.SES();    // This works
var dynamodb = new AWS.DynamoDB();
var docClient = new AWS.DynamoDB.DocumentClient();
AWS.config.update({endpoint: 'http://localhost:8000'});
var ses = new AWS.SES();    // Does not work

var params = {
    Destination: {
        ToAddresses: ['test@example.com']
    },
    Message: {
        Body: { 
            Html: {Data: "This is a test"},
            Text: {Data: "This is a test"}
        },
        Subject: {Data: "Important"}
    },
    Source: '&lt;noreply@example.com&gt;',
};

ses.sendEmail(params, function(err, data) {
    if (err) {
        console.log("Error sending email", err);
    }
    else 
        console.log("Sent email");
});
</code></pre>

<p>The above code sequence gives error. However, if I move the "var ses = new AWS.SES();" statement before DynamoDB then the code works. I am very curious to know what could be the cause</p>