[英]AWS S3 using grails
我正在嘗試建立與aws的連接,以便在s3存儲桶上進行基本操作。 以下是代碼:
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的訪問,所以可以隨時更改。
//初始化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;
您也可以從我的博客中找到運行代碼。
不要忘記添加您的憑據信息:
accountId:@“ xxxxxxxx” identityPoolId:@“ xxxxxxxx-xxxxxxxx” unauthRoleArn:@“ xxxxxxxx-xxxxxxxx-xxxxxxxx-xxxxxxxx”
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.