Calling the invoke API action failed with this message: Network Failure timeout. Using Lambda

0

I am trying to invoke a lambda to store data in a Dynamodb table. In my own AWS account, it works, but not in the company AWS account I'm working at. Cloudwatch does not show any errors. The timeout occurs at "await dynamodb.describeTable(describeParams).promise();".

Calling the invoke API action failed with this message: Network Failure timeout

My code is as follows:

const AWS = require('aws-sdk');
const docClient = new AWS.DynamoDB.DocumentClient();
const dynamodb = new AWS.DynamoDB();

exports.handler = async (event) => {
  const valueTostore = event.body || 'default_value';

  const params = {
    TableName: 'my-values',
    Item: {
      id: new Date().toISOString(),
      SessionConfig: valueTostore
    }
  };

  try {
    const describeParams = { TableName: 'my-values' };
    await dynamodb.describeTable(describeParams).promise();
  } catch (error) {
    const response = {
      statusCode: 500,
      body: JSON.stringify({ message: 'Error while accessing table' })
    };
    return response;
  }

  try {
    await docClient.put(params).promise();
  } catch (error) {
    const response = {
      statusCode: 500,
      body: JSON.stringify({ message: 'Error while storing value' })
    };
    return response;
  }

  const response = {
    statusCode: 200,
    body: JSON.stringify({ message: 'Value stored successfully' })
  };
  return response;
};
combii
asked a year ago1236 views
3 Answers
0
Accepted Answer

Security group for my lambda wasn't configured for outbound rules, so I opened all ports for outbound and it worked! It was a bad error and too broad if AWS sees it, please narrow it down.

combii
answered a year ago
0

I would check that the Lambda has IAM permission to read and write to the DynamoDB table.

AWS
answered a year ago
0

This error message is very generic in lambda. I am assuming you are attempting cross account access since you mentioned using 2 accounts. Not sure which account is your dynamoDb created, but you can start looking into if you have proper IAM permission to access dynamoDB for lambda execution role from your company account. Next you can look if your lambda is created inside your private subnet VPC, then its quite likely that it may not have proper route configured to access dynamoDB. It can be accessed via Internet as well AWS private network using gateway/interface vpc endpoints.

answered a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions