AWSAPIGatewayClient收到API请求错误

时间:2019-04-19 10:01:07

标签: ios objective-c amazon-web-services

Message = "User: arn:aws:sts::XXXX85095:assumed-role/XXXXXX_unauth_MOBILEHUB_XXXX039892/CognitoIdentityCredentials 
is not authorized to perform: execute-api:Invoke on resource: arn:aws:execute-api:ap-southeast-1:********5095:XXXXu7mj
/Dev/POST/XXXXX with an explicit deny";

我正在使用AWS类调用API AWSAPIGatewayClient。我按如下设置代码。

AWSCognitoCredentialsProvider *creds = [[AWSCognitoCredentialsProvider alloc] initWithRegionType:AWSRegionAPSoutheast1 identityPoolId:@"ap-southeast-1_XXXXX"];

AWSServiceConfiguration *configuration2 = [[AWSServiceConfiguration alloc] initWithRegion:AWSRegionAPSoutheast1 credentialsProvider:creds];

AWSServiceManager.defaultServiceManager.defaultServiceConfiguration = configuration2;

AWSAPIGatewayClient *client2 = [[AWSAPIGatewayClient alloc] init];

AWSEndpoint *endPoint = [[AWSEndpoint alloc] initWithRegion:configuration2.regionType

                                                                          service:AWSServiceAPIGateway

                                                                          URL:[NSURL URLWithString:kHostNameGuest]];



AWSSignatureV4Signer *signer = [[AWSSignatureV4Signer alloc] initWithCredentialsProvider:configuration2.credentialsProvider

                                                                                             endpoint:configuration2.endpoint];

configuration2.baseURL = endPoint.URL;

configuration2.requestInterceptors = @[[AWSNetworkingRequestInterceptor new], signer];

[client2 setConfiguration:configuration2];

[[client2 invoke:request] continueWithBlock:^id _Nullable(AWSTask<AWSAPIGatewayResponse *> * _Nonnull t) {

    if (t.result){

                dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul);

        dispatch_async(queue, ^{

        dispatch_sync(dispatch_get_main_queue(), ^{                            

        NSMutableDictionary *jsonObjects = [NSJSONSerialization JSONObjectWithData:t.result.responseData

                                                                                               options:NSJSONReadingAllowFragments

                                                                                                 error:nil];

            NSLog(@"Result =>%@",jsonObjects);                            

                        });

                    });

                }

    if (t.error) {

        dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul);

                dispatch_async(queue, ^{

            dispatch_sync(dispatch_get_main_queue(), ^{

                            NSLog(@"Error: %@", t.error);                      

                        });

                 });

                   return nil;

    }

    return nil;

}]

0 个答案:

没有答案