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 個回答
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
支援工程師
Thabo_M
已回答 1 年前
profile picture
專家
已審閱 1 個月前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南