Amazon.Transfer.Model.InvalidRequestException:无法为 LOGICAL HomeDirectoryType 设置 HomeDirectory

Amazon.Transfer.Model.InvalidRequestException: Cannot set HomeDirectory for LOGICAL HomeDirectoryType

朋友,

我有一个 Dictionary<int, string>,其中包含 DepartmentId 列表及其 s3 文件夹名称。例如,{ {key=1, value="dept-1"}, {key=2, value="dept-2"} } 等。 对于每个 s3 文件夹,我想创建一个逻辑映射到其 SFTP 服务器文件夹的用户 user-dept-group-{DepartmentId}。例如,user-dept-group-1 将有一个逻辑文件夹 dept-1 映射到 aws sftp 服务器中的 my-s3-bucket/dept-1。下面是我使用的代码,我总是收到 Cannot set HomeDirectory for LOGICAL HomeDirectoryType 错误。

如果我评论 HomeDirectoryMappings 并将 HomeDirectoryType 设置为 HomeDirectoryType.PATH,那么我会看到正在创建用户。

public async Task<List<CreateUserResponse>> SetupSftpUser(Dictionary<int, string> masterDeptFolders)
{
    var result = new List<CreateUserResponse>();
    var awsTransferClient = new AmazonTransferClient(AwsAccessKey, AwsSecretKey, RegionEndpoint.USEast1);
    foreach (var (key, folder) in masterDeptFolders)
    {
    var createUserRequest = new CreateUserRequest
    {
        HomeDirectory = $"/{ParentBucketName}/{folder}/",
        HomeDirectoryMappings = new List<HomeDirectoryMapEntry>{new HomeDirectoryMapEntry{Entry = $"/{folder}", Target = $"/{ParentBucketName}/{folder}" } },
        HomeDirectoryType = HomeDirectoryType.LOGICAL,
        // Policy = GetSftpPolicy(),
        Tags = GetTags(key, folder),
        ServerId = SftpServerId,
        UserName = $"user-dept-group-{key}",
        Role = SftpRole,
        //SshPublicKeyBody = "MY_DEPT_SSH.PUB_FILE"
    };

    var response = await awsTransferClient.CreateUserAsync(createUserRequest);
    if (response.HttpStatusCode == HttpStatusCode.OK)
    {
        result.Add(response);
    }
    }

    return result;
}

编辑: 我在所有 examples 中注意到的一件事是 s3 存储桶文件夹名称被提及为 <s3bucket>/home/username。我是否需要具有此文件夹结构才能使其正常工作?

我发现不需要 HomeDirectory,必须将条目值设置为 \。下面是 createUserRequest 的样子。

var createUserRequest = new CreateUserRequest
{
    HomeDirectoryMappings = new List<HomeDirectoryMapEntry>{new HomeDirectoryMapEntry{Entry = "/", Target = $"/{ParentBucketName}/{folder}" } },
    HomeDirectoryType = HomeDirectoryType.LOGICAL,
    // Policy = GetSftpPolicy(),
    Tags = GetTags(key, folder),
    ServerId = SftpServerId,
    UserName = $"user-dept-group-{key}",
    Role = SftpRole,
    //SshPublicKeyBody = "MY_DEPT_SSH.PUB_FILE"
};