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
已提问 1 年前1182 查看次数
3 回答
0
已接受的回答

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
已回答 1 年前
0

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

AWS
已回答 1 年前
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.

已回答 1 年前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则