Search code examples
amazon-web-servicescredentialsamazon-ecsaws-codebuild

Got 404 from http://169.254.170.2/$AWS_CONTAINER_CREDENTIALS_RELATIVE_URI


On AWS ECS or AWS CodeBuild etc, when trying to retrieve as credentials using: http://169.254.170.2/$AWS_CONTAINER_CREDENTIALS_RELATIVE_URI

suddenly since Feb 7, 2019 - I got 404 not found !

curl -qL -o aws_credentials.json http://169.254.170.2/$AWS_CONTAINER_CREDENTIALS_RELATIVE_URI

The expected result should be a valid json of the AWS Credentials session


Solution

  • After short investigation:

    I found that $AWS_CONTAINER_CREDENTIALS_RELATIVE_URI already starts by a slash '/'

    [e.g AWS_CONTAINER_CREDENTIALS_RELATIVE_URI=/v2/credentials/xxxx-xxxx-xxxx-xxxx-xxxxx]
    

    Solution: just remove the slash after the IP.*

    e.g http://169.254.170.2$AWS_CONTAINER_CREDENTIALS_RELATIVE_URI
    

    TL;DR;

    I run curl with -v on AWS CodeBuild:

    > GET //v2/credentials/xxxx-xxxx-xxxx-xxxx-xxxxx HTTP/1.1
    > Host: 169.254.170.2
    > User-Agent: curl/7.47.0
    > Accept: */*
    >
    < HTTP/1.1 404 Not Found
    

    Conclusion: since Feb 6 or 7 2019, AWS add a strict check and broke the request with 404 for double slash //