如何从一个 s3 帐户读取并在 Databricks 中写入另一个帐户
How to read from one s3 account and write to another in Databricks
我的集群配置为使用 ROLE_B,这让我可以访问 BUCKET_IN_ACCOUNT_B 但不能访问 BUCKET_IN_ACCOUNT_A。所以我假设 XACCOUNT_ROLE 访问 BUCKET_IN_ACCOUNT_A。以下代码工作正常。
sc._jsc.hadoopConfiguration().set("fs.s3a.credentialsType", "AssumeRole")
sc._jsc.hadoopConfiguration().set("fs.s3a.stsAssumeRole.arn", XACCOUNT_ROLE)
sc._jsc.hadoopConfiguration().set("fs.s3a.acl.default", "BucketOwnerFullControl")
df = spark.read.option("multiline","true").json(BUCKET_IN_ACCOUNT_A)
但是,当我尝试将此数据帧写回 BUCKET_IN_ACCOUNT_B 时,如下所示,我得到
java.nio.file.AccessDeniedException.
df.write \
.format("delta") \
.mode("append") \
.save(BUCKET_IN_ACCOUNT_B)
我认为是这种情况,因为我的 spark 集群仍配置为使用 XACCOUNT_ROLE。我的问题是,如何切换回 ROLE_B?
sc._jsc.hadoopConfiguration().set("fs.s3a.credentialsType", "AssumeRole")
sc._jsc.hadoopConfiguration().set("fs.s3a.stsAssumeRole.arn", ROLE_B)
sc._jsc.hadoopConfiguration().set("fs.s3a.acl.default", "BucketOwnerFullControl")
没用。
我一直没有找到再次切换集群角色的方法。但我确实想出了一种替代方法来完成从一个 s3 存储桶读取并写入另一个存储桶。基本上,我安装了 XACCOUNT 存储桶并且能够写入 BUCKET_IN_ACCOUNT_B 而不必干扰集群的角色。
dbutils.fs.unmount("/mnt/MOUNT_LOCATION")
dbutils.fs.mount(BUCKET_IN_ACCOUNT_A, "/mnt/MOUNT_LOCATION",
extra_configs = {
"fs.s3a.credentialsType": "AssumeRole",
"fs.s3a.stsAssumeRole.arn": XACCOUNT_ROLE,
"fs.s3a.acl.default": "BucketOwnerFullControl"
}
)
df = spark.read.option("multiline","true").json("/mnt/MOUNT_LOCATION")
df.write \
.format("delta") \
.mode("append") \
.save(BUCKET_IN_ACCOUNT_B)
我的集群配置为使用 ROLE_B,这让我可以访问 BUCKET_IN_ACCOUNT_B 但不能访问 BUCKET_IN_ACCOUNT_A。所以我假设 XACCOUNT_ROLE 访问 BUCKET_IN_ACCOUNT_A。以下代码工作正常。
sc._jsc.hadoopConfiguration().set("fs.s3a.credentialsType", "AssumeRole")
sc._jsc.hadoopConfiguration().set("fs.s3a.stsAssumeRole.arn", XACCOUNT_ROLE)
sc._jsc.hadoopConfiguration().set("fs.s3a.acl.default", "BucketOwnerFullControl")
df = spark.read.option("multiline","true").json(BUCKET_IN_ACCOUNT_A)
但是,当我尝试将此数据帧写回 BUCKET_IN_ACCOUNT_B 时,如下所示,我得到 java.nio.file.AccessDeniedException.
df.write \
.format("delta") \
.mode("append") \
.save(BUCKET_IN_ACCOUNT_B)
我认为是这种情况,因为我的 spark 集群仍配置为使用 XACCOUNT_ROLE。我的问题是,如何切换回 ROLE_B?
sc._jsc.hadoopConfiguration().set("fs.s3a.credentialsType", "AssumeRole")
sc._jsc.hadoopConfiguration().set("fs.s3a.stsAssumeRole.arn", ROLE_B)
sc._jsc.hadoopConfiguration().set("fs.s3a.acl.default", "BucketOwnerFullControl")
没用。
我一直没有找到再次切换集群角色的方法。但我确实想出了一种替代方法来完成从一个 s3 存储桶读取并写入另一个存储桶。基本上,我安装了 XACCOUNT 存储桶并且能够写入 BUCKET_IN_ACCOUNT_B 而不必干扰集群的角色。
dbutils.fs.unmount("/mnt/MOUNT_LOCATION")
dbutils.fs.mount(BUCKET_IN_ACCOUNT_A, "/mnt/MOUNT_LOCATION",
extra_configs = {
"fs.s3a.credentialsType": "AssumeRole",
"fs.s3a.stsAssumeRole.arn": XACCOUNT_ROLE,
"fs.s3a.acl.default": "BucketOwnerFullControl"
}
)
df = spark.read.option("multiline","true").json("/mnt/MOUNT_LOCATION")
df.write \
.format("delta") \
.mode("append") \
.save(BUCKET_IN_ACCOUNT_B)