5

Lambda function - Node.js

const AWS = require('aws-sdk')

exports.handler = async (event) => {
  var appconfig = new AWS.AppConfig({ apiVersion: '2019-10-09' })
  var params = {
    ApplicationId: '6xeris1',
    ConfigurationProfileId: '0ck2ijf'
  }
  const data = await appconfig.getConfigurationProfile(params).promise().catch(err => {
    console.log(err)
  })

  if (data) {
    console.log(data)

    const response = {
      statusCode: 200,
      headers: {
        'Access-Control-Allow-Headers': 'Content-Type',
        'Access-Control-Allow-Origin': '*',
        'Access-Control-Allow-Methods': 'OPTIONS,POST,GET'
      },
      body: JSON.stringify(data)
    }
    return response
  } else {
    const response = {
      statusCode: 500,
      headers: {
        'Access-Control-Allow-Headers': 'Content-Type',
        'Access-Control-Allow-Origin': '*',
        'Access-Control-Allow-Methods': 'OPTIONS,POST,GET'
      },
      body: {}
    }
    return response
  }
}

When getConfigurationProfile is called there is no response. No data, no error and the function get timeout.

I added below inline policy to Lambda execution IAM role, but it didn't work.

"Action": "appconfig:*"

Anyone solved this issue before me? Thank you.

Kim-Jimin
  • 674
  • 2
  • 9
  • 19

1 Answers1

4

Based on the comments.

The issue was due to the fact that lambda function was configure to be in a VPC. However, functions in VPC don't have internet access nor public IP. From docs:

Connecting a function to a public subnet doesn't give it internet access or a public IP address.

The solution was to use VPC endpoint.

Marcin
  • 215,873
  • 14
  • 235
  • 294
  • 1
    Thank you. The lambda function should be in VPC to connect RDS, and VPC endpoint was useful. But your comment helped me solve this issue faster. Thanks. – Kim-Jimin Aug 23 '20 at 10:21
  • @Kim-Jimin Thanks for letting me know. I will add vpc endpoint to the answer. – Marcin Aug 23 '20 at 10:22