Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/amazon-web-services/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/wix/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用grails的awss3_Java_Amazon Web Services_Grails_Amazon S3_Aws Sdk - Fatal编程技术网

Java 使用grails的awss3

Java 使用grails的awss3,java,amazon-web-services,grails,amazon-s3,aws-sdk,Java,Amazon Web Services,Grails,Amazon S3,Aws Sdk,我正在尝试建立与aws的连接,以便在s3 bucket上完成基本操作。代码如下: def list(){ AWSCredentials credentials = new BasicAWSCredentials("Access key", "Secret Key"); AmazonS3 s3client = new AmazonS3Client(credentials); String bucketName = "sample-bucket

我正在尝试建立与aws的连接,以便在s3 bucket上完成基本操作。代码如下:

def list(){
        AWSCredentials credentials = new BasicAWSCredentials("Access key", "Secret Key");


        AmazonS3 s3client = new AmazonS3Client(credentials);


        String bucketName = "sample-bucket-from-java-code";



        System.out.println("Listing all buckets : ");
        for (Bucket bucket : s3client.listBuckets()) {
            System.out.println(" - " + bucket.getName());
        }
    }
这给了我一个错误:

request- Received error response: com.amazonaws.services.s3.model.AmazonS3Exception: The request signature we calculated does not match the signature you provided. Check your key and signing method.
我还仔细检查了我使用的访问密钥和密钥。无法找出问题所在。

最好使用“cognito accountId”,而不是访问和密钥。因为使用cognito accountID对AWS的访问是有限的,而AWS总是可以更改的

//初始化Amazon Cognito凭据提供程序

AWSCognitoCredentialsProvider* credentialsProvider = [AWSCognitoCredentialsProvider
                                                      credentialsWithRegionType:AWSRegionUSEast1
                                                      accountId:@"xxxxxxxxxxx"
                                                      identityPoolId:@"xxxxxxxxxxx"
                                                      unauthRoleArn:@"arn:aws:iam::xxxxxxxxxxx"
                                                      authRoleArn:nil];

AWSServiceConfiguration* configuration = [AWSServiceConfiguration configurationWithRegion:AWSRegionUSWest2
                                                                      credentialsProvider:credentialsProvider];

[AWSServiceManager defaultServiceManager].defaultServiceConfiguration = configuration;
您还可以从我的博客中找到运行代码

不要忘记添加您的凭证信息:

帐户ID:@“xxxxxxxx” identityPoolId:@“xxxxxxxx-xxxxxxxx”
学习:@“xxxxxxxx-xxxxxxxx-xxxxxxxx-xxxxxxxx-xxxxxxxx”

您是否检查过IAM用户和角色是否同样灵活,并且通常在这种情况下使用。@tauheed提供了另一种选择。同意Mark!