Search code examples
apiamazon-ec2amazon-cloudfrontregion

AWS Cloudfront: Credential should be scoped to a valid region


When connecting to AWS CloudFront via the API, no matter what I do, I get the Exception:

Credential should be scoped to a valid region

The same credentials work on any other request the account has permissions for, like S3.


Solution

  • The Exception is caused by accessing CloudFront with any Region set other than "us-east-1". Because CloudFront is basically regionless, it requires you to use only the default region "us-east-1" to talk to it.

    http://docs.aws.amazon.com/general/latest/gr/signature-v4-troubleshooting.html

    You can workaround this by using the same credentials you use elsewhere but instantiate the CloudFront client with the Region explicitly set:

    AmazonCloudFrontClient client = new AmazonCloudFrontClient(Amazon.RegionEndpoint.USEast1);
    

    Which does beg the follow-on question: Why does the API not just do this for you?

    Edit: Issue posted. https://github.com/aws/aws-sdk-net/issues/115