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
posta un anno fa1182 visualizzazioni
3 Risposte
0
Risposta accettata

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
con risposta un anno fa
0

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

AWS
con risposta un anno fa
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.

con risposta un anno fa

Accesso non effettuato. Accedi per postare una risposta.

Una buona risposta soddisfa chiaramente la domanda, fornisce un feedback costruttivo e incoraggia la crescita professionale del richiedente.

Linee guida per rispondere alle domande