Cant connect dynamo Db from my vpc configured lambda function : <p>i need to connect elastic cache and dynamo db from a single lambda function. My code is</p>

<pre><code>exports.handler = (event, context, callback) =&gt; {

    var redis = require("redis");
    var client;
    function connectRedisClient() {
        client = redis.createClient(6379, "dgdfgdfgdfgdfgdfgfd.use1.cache.amazonaws.com", { no_ready_check: true });
    }

    connectRedisClient();
    client.set('sampleKey', 'Hello World', redis.print);
    console.log("set worked");
    client.quit();


    var AWS = require("aws-sdk");
    var docClient = new AWS.DynamoDB.DocumentClient();
    var table = "dummy";
    var year = 2015;
    var title = "The Big New Movie";
    var params = {
        TableName: table,
        Item: {
            "userid": "manafcj",
            "year": year,
            "title": title,
            "test1": [645645, 7988],
            "info": {
                "plot": "Nothing happens at all.",
                "rating": 0
            }
        }
    };

    console.log("Adding a new item...");
    docClient.put(params, function (err, data) {
        if (err) {
            console.error("Unable to add item. Error JSON:", JSON.stringify(err, null, 2));
        } else {
            console.log("Added item:", JSON.stringify(data, null, 2));
        }
    });
    callback(null, 'Hello from Lambda');
 }; 
</code></pre>

<p>I executed this lambda code without configuring vpc, elastic cache section is not working , but dynamo insertion is done perfectly.</p>

<p>after that i made setup for VPC in my account by following steps.</p>

<ol>
<li><p>create vpc 
name : test-vpc-name
CIDR block:172.31.0.0/16
Tenancy:Default</p></li>
<li><p>Create a new subnet.
name tag : test-subnet-1a
CIDR block :172.31.0.0/20</p>

<p>name tag : test-subnet-1b
CIDR block :172.31.16.0/20</p></li>
<li><p>Create a route table
name tag : test-route-table</p></li>
<li><p>Create a internet gateway
name:test-internet-gateway</p></li>
<li><p>Attach VPC</p></li>
<li><p>Route all outbound 0.0.0.0/0 traffic in routes</p></li>
<li><p>Create a route table subnet association</p></li>
<li><p>Create a NAT Gateway
subnet : test-subnet-1a</p></li>
</ol>

<p>also i have configured my elastic cache setup by following steps</p>

<ol>
<li><p>Create subnet cache group
name : test-cache-group</p></li>
<li><p>Create elastic cache<br>
type: redis
Cluster Name : test-cache</p>

<p>subnet cache group :  test-cache-group</p></li>
</ol>

<p>Finally, i have configured newly created vpc on my lambda function. Then redis-elastic cache connection is working fine, but dynamo db connection is lost. I need both working fine from a single lambda function.</p>

<p>I think, some fault in VPC configuration with NAT Gateway. </p>

<p>What is the actual issue in this setup?</p>
