web-dev-qa-db-ja.com

AWSIOT-サービスを修正するために認証情報のスコープを設定する必要があります

単純なAWSIOT RESTサービスにアクセスしようとしていますが、まだ正常にアクセスできていません。これが私が行ったことです。

  1. 私は自分のawsでiamユーザーを作成し、アクセスキーとシークレットキーをダウンロードしました
  2. そのユーザーでAWSIOTにログインし、「モノ」を作成しました
  3. 物のプロパティから、私は影のREST URLを見つけました
  4. Postmanを新しい「awssignature」機能で使用し、アクセスキー、シークレットキー、リージョン(us-east-1)、サービス名(iot)を提供しました
  5. エンドポイントを「GET」しようとしましたが、これが私が得たものです-

    { "message": "Credential should be scoped to correct service. ", "traceId": "be056198-d202-455f-ab85-805defd1260d" }

  6. Postmanに問題があると思ったので、S3に接続するaws-sdk-sampleの例を使用して、IOTURLに接続するように変更しました。これが私のプログラムスニペットです(Java)

    String awsAccessKey = "fasfasfasdfsdafs";
    String awsSecretKey = "asdfasdfasfasdfasdfasdf/asdfsdafsd/fsdafasdf";
    
    URL  endpointUrl = null;
    String regionName = "us-east-1";
    try {
        endpointUrl = new URL("https://dasfsdfasdf.iot.us-east-1.amazonaws.com/things/SOMETHING/shadow");
    }catch (Exception e){
        e.printStackTrace();
    }
    Map<String, String> headers = new HashMap<String, String>();
    headers.put("x-amz-content-sha256", AWSSignerBase.EMPTY_BODY_SHA256);
    
    AWSSignerForAuthorizationHeader signer = new AWSSignerForAuthorizationHeader(
            endpointUrl, "GET", "iot", regionName);
    String authorization = signer.computeSignature(headers,
            null, // no query parameters
            AWSSignerBase.EMPTY_BODY_SHA256,
            awsAccessKey,
            awsSecretKey);
    
    // place the computed signature into a formatted 'Authorization' header
    // and call S3
    headers.put("Authorization", authorization);
    String response = HttpUtils.invokeHttpRequest(endpointUrl, "GET", headers, null);
    System.out.println("--------- Response content ---------");
    System.out.println(response);
    System.out.println("------------------------------------");
    

これは私に同じエラーを与えます-

--------- Request headers ---------
x-amz-content-sha256: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
Authorization: AWS4-HMAC-SHA256 Credential=fasfasfasdfsdafs/20160212/us-east-1/iot/aws4_request, SignedHeaders=Host;x-amz-content-sha256;x-amz-date, Signature=3b2194051a8dde8fe617219c78c2a79b77ec92338028e9e917a74e8307f4e914
x-amz-date: 20160212T182525Z
Host: dasfsdfasdf.iot.us-east-1.amazonaws.com
--------- Response content ---------
{"message":"Credential should be scoped to correct service. ","traceId":"cd3e0d96-82fa-4da5-a4e1-b736af6c5e34"}
------------------------------------

誰かが私が間違っていることを教えてもらえますか? AWSのドキュメントには、このエラーに関する多くの情報がありません。助けてください

15
Robby

iotdataの場合は、代わりにiotでリクエストに署名してください
例:

AWSSignerForAuthorizationHeader signer = new AWSSignerForAuthorizationHeader(
    endpointUrl, "GET", "iotdata", regionName);
11
Firas Al Mannaa

基本的にサービス名が正しく指定されていないため、iotの代わりにサービス名= 'iotdata'を使用できます。

キー管理を使用する場合、サービス名はkmsになります。 EC2の場合、サービス名はec2などになります。

0
kartick shaw