localstack icon indicating copy to clipboard operation
localstack copied to clipboard

Empty result when calling get ssm parameters by path with HTTP

Open ldrag opened this issue 5 years ago • 6 comments

Hi, since version 0.12.17 an http call to get ssm parameters by path always returns empty result set.

To reproduce: Add a sample parameter to SSM with cli: awslocal ssm put-parameter --type String --name /some-path/some-parameter --value some-value

Verify that it is there: awslocal ssm get-parameters-by-path --path /some-path/

The response is similar to:

{
    "Parameter": {
        "Name": "/some-path/some-parameter",
        "Type": "String",
        "Value": "some-value",
        "Version": 1,
        "LastModifiedDate": 1637923738.669,
        "ARN": "arn:aws:ssm:eu-west-1:000000000000:parameter/some-path/some-parameter"
    }
}

However issuing a HTTP call like:

POST http://localhost:4566
X-Amz-Target: AmazonSSM.GetParametersByPath
Content-Type: application/x-amz-json-1.1
amz-sdk-invocation-id: 0b7602f9-6c56-3800-70b2-35c691659f66
X-Amz-Date: 20211126T095752Z
Authorization: AWS4-HMAC-SHA256 Credential=key/20211126/us-east-1/ssm/aws4_request, SignedHeaders=amz-sdk-invocation-id;amz-sdk-request;amz-sdk-retry;content-length;content-type;host;user-agent;x-amz-date;x-amz-target, Signature=39c3b3042cd2aEXAMPLE
{
  "Path": " /some-path/"
}

Ends with an empty response: {"Parameters": [], "NextToken": null}

whereas in versions < 0.12.17 the result of such a call would be: {"Parameters": [{"Name": "/some-path/some-parameter", "Type": "String", "Value": "some-value", "Version": 1, "LastModifiedDate": 1637924362.244, "ARN": "arn:aws:ssm:eu-west-1:000000000000:parameter/some-path/some-parameter"}], "NextToken": null}

Please have a look what might be wrong. Thanks.

ldrag avatar Nov 26 '21 11:11 ldrag

@ldrag this should be fixed in the latest release. I just tested your issue with this code:

awslocal ssm put-parameter --type String --name /some-path/some-parameter --value some-value
awslocal ssm get-parameters-by-path --path /some-path/

curl -H "Content-Type: application/x-amz-json-1.1" \
	-H "X-Amz-Target: AmazonSSM.GetParametersByPath" \
	-H "amz-sdk-invocation-id: 0b7602f9-6c56-3800-70b2-35c691659f66" \
	-H "X-Amz-Date: 20211126T095752Z" \
	-H "Authorization: AWS4-HMAC-SHA256 Credential=key/20211126/us-east-1/ssm/aws4_request, SignedHeaders=amz-sdk-invocation-id;amz-sdk-request;amz-sdk-retry;content-length;content-type;host;user-agent;x-amz-date;x-amz-target, Signature=39c3b3042cd2aEXAMPLE" \
        -X POST \
        -d '{"Path":"/some-path"}' \
        http://localhost:4566

Result from awscli:

{
    "Version": 1
}
{
    "Parameters": [
        {
            "Name": "/some-path/some-parameter",
            "Type": "String",
            "Value": "some-value",
            "Version": 1,
            "LastModifiedDate": 1638984380.109,
            "ARN": "arn:aws:ssm:us-east-1:000000000000:parameter/some-path/some-parameter",
            "DataType": "text"
        }
    ]
}

Result from POST request:

{"Parameters": [{"Name": "/some-path/some-parameter", "Type": "String", "Value": "some-value", "Version": 1, "LastModifiedDate": 1638984380.109, "DataType": "text", "ARN": "arn:aws:ssm:us-east-1:000000000000:parameter/some-path/some-parameter"}], "NextToken": null}

Let me know if it continues to fail for you.

pinzon avatar Dec 08 '21 17:12 pinzon

@pinzon thank you for investigation. Unfortunately I still have an empty response for POST request. I am using latest docker image of localstack:

LocalStack version: 0.13.1
LocalStack build date: 2021-12-08
LocalStack build git hash: 88945ec4

Which version did work for you?

ldrag avatar Dec 09 '21 09:12 ldrag

Yesterday I tried with 13.0.10 and just now I tried with 13.1 both work. Maybe it is the way you start Localstack or your setup. Could you provide more info?

pinzon avatar Dec 09 '21 16:12 pinzon

I am using localstack within my docker-compose. The relevant part looks like this

  localstack:
    image: localstack/localstack
    environment:
      - SERVICES=ssm,sns,sqs,sts
      - DEFAULT_REGION=eu-west-1
      - HOSTNAME_EXTERNAL=localstack
    volumes:
      - ./infra/local:/docker-entrypoint-initaws.d
    expose:
      - "4566"

I have tried issuing POST requests from docker container and docker host and both returned empty parameters. The problem appears both on my Windows machine (with WSL2 docker engine) and Linux CI environment.

Are you aware of any change between versions 0.12.16 and 0.12.17 that could somehow be related? Please let me know if any additional info would be helpful for you.

ldrag avatar Dec 09 '21 18:12 ldrag

Hi @ldrag thank you for your patience. I took the time to re-triage your issue and running localstack in a windows environment with WSL works fine.

After having a similar situation about what you described I found out that the issue is not with Windows but with the request headers.

You're setting the default region to eu-west-1, creating a resource and then sending a find request with us-east-1 in your Authorization header. The AWS SSM service resources are divided by region (mostly all resources are) so make sure to check in what region your resource is created when looking for it.

By the way, it was recently that Localstack started imitating this AWS behaviour.

pinzon avatar Dec 22 '21 17:12 pinzon

Thank you @pinzon this was indeed a problem of incorrect region.

The HTTP call with a wrong region is in my case called by a Spring Boot application with spring cloud libraries on board. In production environment they discover they region by examining the endpoint url e.g. https://ssm.eu-west-1.amazonaws.com. In case of my local setup the endpoint is http://localstack:4566, therefore it always defaulted to 'us-east-1'. As I did not figure out how to change it (I tried both HOSTNAME and HOSTNAME_EXTERNAL docker variables) I ended up by enabling the legacy single region mode with USE_SINGLE_REGION.

ldrag avatar Dec 27 '21 05:12 ldrag