I'm facing a problem with my TypeScript application that involves utilizing the AWS SDK. My objective is to retrieve the Feature Flag I set up in my AWS AppConfig. The error message currently displayed is:
Error getting AppConfig configuration: Error: connect ECONNREFUSED 169.254.169.254:80
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1555:16) {
message: 'Missing credentials in config, if using AWS_CONFIG_FILE, set AWS_SDK_LOAD_CONFIG=1',
errno: -111,
code: 'CredentialsError',
syscall: 'connect',
address: '169.254.169.254',
port: 80,
time: 2023-12-14T16:21:24.678Z,
originalError: {
message: 'Could not load credentials from any providers',
errno: -111,
code: 'CredentialsError',
syscall: 'connect',
address: '169.254.169.254',
port: 80,
time: 2023-12-14T16:21:24.678Z,
originalError: {
message: 'EC2 Metadata roleName request returned error',
errno: -111,
code: 'ECONNREFUSED',
syscall: 'connect',
address: '169.254.169.254',
port: 80,
time: 2023-12-14T16:21:24.677Z,
originalError: [Object]
}
}
}
The code snippet I am using is as follows:
import { Request, Response, NextFunction } from 'express';
import AWS from "aws-sdk";
const { AppConfig } = AWS;
const appConfig = new AppConfig({region: "us-east-1"});
const params = {
Application: '**********',
Configuration: '**********',
Environment: '**********',
ClientId: "**********"
};
const response = await appConfig.getConfiguration(params).promise();
const featureFlags: { [key: string]: boolean } = JSON.parse(response.Content!.toString());
return featureFlags[featureName];
} catch (error) {
console.error('Error getting AppConfig configuration:', error);
throw error;
}
My current approach is based on the guidance provided by AWS documentation, but I am open to exploring alternative methods. I am uncertain about the root cause of the issue. The configurations supplied are directly from AWS, so they should be accurate. Do I need to enable anything in AWS AppConfig to access the Feature Flags that I have configured? Is there another way to achieve this task?
Your assistance in resolving this matter would be greatly appreciated!