将 API 文件加载到 S3 中的子文件夹时粘合作业失败

发布于 2025-01-16 05:51:43 字数 631 浏览 1 评论 0原文

我对此很陌生。 我使用 python 脚本创建了一个简单的 Glue 作业,用于发送 API 请求并将数据加载到 S3 中。将数据加载到顶部 S3 存储桶 (s3://my-bucket) 时,它工作正常,但当我更改目标目录以将文件加载到 S3 的子目录 (s3://my-bucket/log-data) 时,作业失败。 以下脚本可以将文件 mydata.txt 加载到存储桶中。

import request
import boto3
URL = "https://jsonplaceholder.typicode.com/todos/1"
r = requests.get(url = URL)
s3_client = boto3.client('s3',region_name='eu-west-2')
s3_client.put_object(Body=r.text, Bucket='my-bucket', Key='mydata.txt')` ' 

当我更改代码的最后一行以将文件加载到 S3 存储桶的子目录中时,

s3_client.put_object(Body=r.text, Bucket='my-bucket/log-data', Key='mydata.txt')

任何建议将不胜感激。 谢谢,

I'm new to this.
I've created a simple Glue job with python script that send API request and load data into S3. When loading data into the top S3 bucket (s3://my-bucket) it works fine but the job fails when I change the target directory to load files into subdirectory of S3 (s3://my-bucket/log-data).
the following script works and load file mydata.txt into the bucket.

import request
import boto3
URL = "https://jsonplaceholder.typicode.com/todos/1"
r = requests.get(url = URL)
s3_client = boto3.client('s3',region_name='eu-west-2')
s3_client.put_object(Body=r.text, Bucket='my-bucket', Key='mydata.txt')` ' 

when I change the last line of the code to load file into the subdirectory of S3 bucket

s3_client.put_object(Body=r.text, Bucket='my-bucket/log-data', Key='mydata.txt')

Any advice will be much appreciated.
Thanks,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

居里长安 2025-01-23 05:51:43

尝试将前缀添加到 put_object 中的 Key arg

import request
import boto3
URL = "https://jsonplaceholder.typicode.com/todos/1"
r = requests.get(url = URL)
s3_client = boto3.client('s3',region_name='eu-west-2')
s3_client.put_object(Body=r.text, Bucket='my-bucket', Key='log-data/mydata.txt')

Try adding the prefix to the Key arg in put_object

import request
import boto3
URL = "https://jsonplaceholder.typicode.com/todos/1"
r = requests.get(url = URL)
s3_client = boto3.client('s3',region_name='eu-west-2')
s3_client.put_object(Body=r.text, Bucket='my-bucket', Key='log-data/mydata.txt')
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文