spring-cloud-aws icon indicating copy to clipboard operation
spring-cloud-aws copied to clipboard

Parameter Store property "spring.cloud.aws.parameterstore.endpoint" is not loaded correctly when declared in an "application.properties" of a specifc spring profile

Open HenriqueDelben opened this issue 1 year ago • 6 comments

Type: Bug

Component: Parameter Store

Describe the bug The property "spring.cloud.aws.parameterstore.endpoint" is not loaded correctly when specified under a specific application.properties profile

Ex.:

# application.properties 
spring.cloud.aws.parameterstore.endpoint=http://ssm.sa-east-1.amazonaws.com
# application-dev.properties
spring.cloud.aws.parameterstore.endpoint=http://localhost:4566

If the application is executed with:

java -jar app.jar --spring.profiles.active=dev

The expected endpoint to be used by Spring Cloud AWS's auto-configured SsmClient would be "http://localhost:4566". But instead, "http://ssm.sa-east-1.amazonaws.com" is used.

Sample

# application-dev.properties 
spring.cloud.aws.parameterstore.endpoint=http://localhost:4566

Making a GET request with "dev" profile active to "/teste":

@RestController
public class ControllerParameterStore {

    @Value("${foo}")
    public String foo;
    private final ServiceParameterStore serviceParameterStore;

    public ControllerParameterStore(ServiceParameterStore serviceParameterStore) {

        this.serviceParameterStore = serviceParameterStore;
    }

    @GetMapping("/teste")
    public String teste() {
        return foo;
    }
}

Should return "foo from localhost:4566". As stated here:

2023-11-20T17:45:39.054-03:00 INFO 80862 --- [ restartedMain] com.example.demo.DemoApplication : The following 1 profile is active: "dev"

And showed here:

aws ssm get-parameter --name foo --with-decryption --endpoint-url http://localhost:4566
{
    "Parameter": {
        "Name": "foo",
        "Type": "SecureString",
        "Value": "foo from localhost:4566",
        "Version": 1,
        "LastModifiedDate": "2023-11-20T17:40:12.731000-03:00",
        "ARN": "arn:aws:ssm:sa-east-1:000000000000:parameter/foo",
        "DataType": "text"
    }
}

Instead returns this: "foo from amazon sa-east-1 server". From the default aws server (configured automatically I think), as you can see here

aws ssm get-parameter --name foo --with-decryption 
{
    "Parameter": {
        "Name": "foo",
        "Type": "SecureString",
        "Value": "foo from amazon sa-east-1 server",
        "Version": 1,
        "LastModifiedDate": "2023-11-20T17:41:51.835000-03:00",
        "ARN": "arn:aws:ssm:sa-east-1:0000000000:parameter/foo",
        "DataType": "text"
    }

HenriqueDelben avatar Nov 20 '23 20:11 HenriqueDelben

Hey @HenriqueDelben , which spring boot version are you using?

MatejNedic avatar Nov 21 '23 18:11 MatejNedic

Hey, I’m using version 3.1.3

HenriqueDelben avatar Nov 21 '23 18:11 HenriqueDelben

This is blocking my team as well. Neither spring.cloud.aws.parameterstore.endpoint nor spring.cloud.aws.endpoint have any effect.

miles-po avatar Feb 16 '24 18:02 miles-po

@HenriqueDelben @miles-po i am not able to reproduce it. Here's the working sample: https://github.com/maciej-scratches/spring-cloud-aws-gh-966

Please provide a sample that reproduces this issue and if the issue really exists, ideally PR with a fix.

maciejwalkowiak avatar Feb 17 '24 15:02 maciejwalkowiak

I am seeing the same problem, endpoint is not being picked up from my SQS config:

cloud:
  aws:
    endpoint: http://localhost:4566
    region:
      auto: false
      static: us-east-2
    stack:
      auto: false
    credentials:
      accessKey: zalupa
      secretKey: zalupa

As a result, I get:

Caused by: com.amazonaws.services.sqs.model.QueueDoesNotExistException: The specified queue does not exist for this wsdl version. (Service: AmazonSQS; Status Code: 400; Error Code: AWS.SimpleQueueService.NonExistentQueue; Request ID: O9SD4TM5SUQ3X03HI0QL9D41RAF1ESHT6YTWWMRB2OQMYSGD736F; Proxy: null)
	at com.amazonaws.http.AmazonHttpClient$RequestExecutor.handleErrorResponse(AmazonHttpClient.java:1879)
	at com.amazonaws.http.AmazonHttpClient$RequestExecutor.handleServiceErrorResponse(AmazonHttpClient.java:1418)
	at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeOneRequest(AmazonHttpClient.java:1387)
	at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeHelper(AmazonHttpClient.java:1157)

Running with Spring Boot v2.7.18, Spring v5.3.33, Spring Cloud AWS v2.4.4

If I modify the region value, I can see the endpoint value changing if I inspect in debug mode paramRealSQS.

Line 110 of AmazonSQSBufferedAsyncClient :

public AmazonSQSBufferedAsyncClient(AmazonSQSAsync paramRealSQS) {
    this(paramRealSQS, new QueueBufferConfig());
}

imochurad avatar Mar 21 '24 02:03 imochurad

Hi I'm able to reproduce the issue like below configs. I have 2 config files: application.yml

spring:
    config:
      import: optional:aws-parameterstore:/gotyme/cico-voucher/feature-flags/

application-local.yml

spring:
    cloud:
      aws:
        endpoint: http://localhost:4566
        parameterstore:
          endpoint: http://localhost:4566

When I run the application with local profile, other configs from application-local.yml was correctly loaded except the aws.endpoint.

Workaround solutions: put the spring.config.import and spring.cloud.aws.endpoint in the same file, either application.yml or application-local.yml both will work.

  1. Move the aws.endpoint or aws.parameterstore.endpoint to the application.yml
  2. Move the spring.config.import to the application-local.yml

tuyennta avatar Aug 19 '24 00:08 tuyennta