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
demandé il y a un an1182 vues
3 réponses
0
Réponse acceptée

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
répondu il y a un an
0

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

AWS
répondu il y a un an
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.

répondu il y a un an

Vous n'êtes pas connecté. Se connecter pour publier une réponse.

Une bonne réponse répond clairement à la question, contient des commentaires constructifs et encourage le développement professionnel de la personne qui pose la question.

Instructions pour répondre aux questions