以编程方式在AWS S3上启用版本控制

时间:2015-06-06 00:05:19

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

我无法使用AWS SDK iOS v2.1.1以编程方式启用现有存储桶的版本控制。错误是-[NSNull _fastCharacterContents]: unrecognized selector sent to instance ...。我的代码片段会因执行putBucketVersioning方法而产生错误:

    AWSS3VersioningConfiguration *conf = [AWSS3VersioningConfiguration new];
    conf.status = AWSS3BucketVersioningStatusEnabled;

    AWSS3PutBucketVersioningRequest *versionRequest = [AWSS3PutBucketVersioningRequest new];
    versionRequest.bucket = createBucketReq.bucket;
    versionRequest.versioningConfiguration = conf;

    [[[AWSS3 S3ForKey:key] putBucketVersioning:versionRequest] continueWithBlock:^id(BFTask *task) {

        return task;
}

我可能在如何创建AWSS3PutBucketVersioningRequest请求时错过了一个论点,但我找不到任何可以指向正确方向的示例或文档。 Java,Cocoa或Swift中的任何建议都是非常受欢迎的。干杯,特隆德

更新

基于注释,我在启用AWSLogging详细信息后包含完整方法和错误输出。

-(BFTask*) enableVersioningOfBucket:(NSString*)bucket region:(NSInteger) region {

    [self setupCredentialsForRegion:region];
    NSString *key = [NSString stringWithFormat:@"regionkey%li",region];

    AWSS3VersioningConfiguration *conf = [AWSS3VersioningConfiguration new];
    conf.status = AWSS3BucketVersioningStatusEnabled;

    AWSS3PutBucketVersioningRequest *versionRequest =  [AWSS3PutBucketVersioningRequest new];
    versionRequest.bucket = bucket;
    versionRequest.versioningConfiguration = conf;
    NSLog(@"Config %@",versionRequest);

   return [[[AWSS3 S3ForKey:key] putBucketVersioning:versionRequest] continueWithBlock:^id(BFTask *task) {
        NSLog(@"Put bucket versioning %@ - %@", task, task.result);
        return task;
    }];
} 

记录消息:

    2015-06-06 12:09:41.822 connectS3[50137:6337899] Config <AWSS3PutBucketVersioningRequest: 0x600000082350> {
    bucket = testbucket;
    versioningConfiguration = "<AWSS3VersioningConfiguration: 0x600000024bc0> {\n    MFADelete = 0;\n    status = 1;\n}";}
    2015-06-06 12:09:41.832 connectS3[50137:6337899] -[NSNull _fastCharacterContents]: unrecognized selector sent to instance 0x7fff7724c210

更新2

下图显示了堆栈跟踪,因为当我使用断点并进入每个方法调用时,错误消息刚刚出现。 enter image description here

更新3 我按照下面的说明设置了我的凭据。除了启用版本控制之外,这适用于我与S3连接的所有其他方法。

        AWSStaticCredentialsProvider *credentialsProvider = [[AWSStaticCredentialsProvider alloc ]
                                                           initWithAccessKey:keychainStore[ACCESS_KEY_ID]
                                                             secretKey:keychainStore[SECRET_KEY]];

        AWSServiceConfiguration *configuration = [[AWSServiceConfiguration alloc] initWithRegion:region
                                                           credentialsProvider:credentialsProvider];

        /* One credential configuration for each region **/
        NSString *key = [NSString stringWithFormat:@"regionkey%li",region];
        [AWSS3 registerS3WithConfiguration:configuration forKey:key];

        /* Default credentialsProvider **/
        [AWSServiceManager defaultServiceManager].defaultServiceConfiguration = configuration;

感谢您的帮助!

1 个答案:

答案 0 :(得分:1)

我可以确认它是当前AWS Mobile SDK中的一个错误。我们将在以后的版本中修复它。感谢您的报道。

要获得解决方法,您可以在AWSS3VersioningConfiguration代码中添加以下行:

AWSS3VersioningConfiguration *conf = [AWSS3VersioningConfiguration new];
    conf.status = AWSS3BucketVersioningStatusEnabled;
    conf.MFADelete = AWSS3MFADeleteDisabled; // <------ Add this line
...