Unable to use AWS Parameters and Secrets Lambda Extension

0

Hello

I tried all the steps required to use AWS Parameters and Secrets Lambda Extension such like adding layer and using the X-Aws-Parameters-Secrets-Token in the header but the problem is when I call the request to get the secrets by using AWS Lambda Extension I get the "feign.RetryableException: Connection refused (Connection refused) executing GET http://localhost:2773/secretsmanager/get?secretId=test" problem.

Error : Connection refused (Connection refused) executing GET http://localhost:2773/secretsmanager/get?secretId=test" problem.

I really do not understand the problem. The token seems fine as well. I used Feign Client to make a GET request to call the secrets by using AWS Lambda Extension . Could you please check the implementation and let me know the problem?

//* SecretsAndParametersExtensionAPI class (API class for Feign Client) 
 @Headers({"X-Aws-Parameters-Secrets-Token: {token}"})
 public interface SecretsAndParametersExtensionAPI { // TODO move me

 @RequestLine("GET /secretsmanager/get")
 @Headers("X-Aws-Parameters-Secrets-Token: {token}")
 String getSecret(@Param("token") String token, @QueryMap Map<String, Object>    queryMap);
 }

// Test class to get Secrets by using AWS Secrets Parameters Lambda Extension
@Test
public void testSecretsExtension() {

String sessionToken = EnvVarCommon.SESSION_TOKEN.get();
System.out.println(sessionToken);

try {
  SecretsAndParametersExtensionAPI secretsAndParametersExtensionAPI =
      Feign.builder().target(SecretsAndParametersExtensionAPI.class, "http://localhost:2773/");

  Map<String, Object> queryMap = new HashMap<>();
  queryMap.put("secretId", "test");

  String resultFromSecretExtension =
      secretsAndParametersExtensionAPI.getSecret(sessionToken, queryMap);

  System.out.println("Result From Secret Extension " + resultFromSecretExtension);
  log.debug("Request sent to ULH and ULH send request to LAVIN to download profile picture");

} catch (IllegalStateException | JsonSyntaxException exception) {
  log.error(
      "Failed to get response from ULH for downloading profile picture for the UserID '{}'",
      exception);
}
}

 //* template.yml file (CloudFormation file for adding Layer) 
 Mappings:
RegionToLayerArnMap:
us-east-1:
  "LayerArn": "arn:aws:lambda:us-east-1:177933569100:layer:AWS-Parameters-and-Secrets-Lambda-Extension:2"
us-east-2:
  "LayerArn": "arn:aws:lambda:us-east-2:590474943231:layer:AWS-Parameters-and-Secrets-Lambda-Extension:2"
eu-west-1:
  "LayerArn": "arn:aws:lambda:eu-west-1:015030872274:layer:AWS-Parameters-and-Secrets-Lambda-Extension:2"
eu-west-2:
  "LayerArn": "arn:aws:lambda:eu-west-2:133256977650:layer:AWS-Parameters-and-Secrets-Lambda-Extension:2"
eu-west-3:
  "LayerArn": "arn:aws:lambda:eu-west-3:780235371811:layer:AWS-Parameters-and-Secrets-Lambda-Extension:2"


AlperTestBotLambda:
Type: AWS::Serverless::Function
Condition: EnableAlperTestbot
Properties:
  Tracing: Active
  Runtime: java11
  Environment:
    Variables:
      component: !Ref Component
      componentShortName: !Ref ComponentShortName
      version: !Ref Version
      zone: !Ref Zone
      tenant: !Ref Tenant
      testTenant: "test"
      alperTestQueueName: !Ref AlperTestQueueName
      aws.sessionToken: !Ref SessionToken
  Policies:
    - !Ref SecureParameterAccess
    - !Ref PurgeSqsPolicyTestQueues
  EventInvokeConfig:
    MaximumRetryAttempts: 0
  Layers:
    - !FindInMap [ RegionToLayerArnMap, !Ref "AWS::Region", LayerArn ]
1 Answer
0

Hello

Connection refused means that the port you are trying to connect to is not open. This could mean the extension is not loaded or is perhaps listening on a different port. You should be able to confirm that the AWS Parameters and Secrets Lambda Extension is being loaded and serving on the right port by looking at the Lambda function CloudWatch logs.

Please look for similar entries:

[AWS Parameters and Secrets Lambda Extension] INFO Serving on port 2773 EXTENSION Name: AWSParametersAndSecretsLambdaExtension State: Ready

https://docs.aws.amazon.com/secretsmanager/latest/userguide/retrieving-secrets_lambda.html

AWS
SUPPORT ENGINEER
Thabo_M
answered a year ago
profile picture
EXPERT
reviewed 23 days ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions