python subprocess.call()返回lambda函数中的null响应AWS

发布于 2025-02-06 09:13:14 字数 656 浏览 2 评论 0原文

我需要运行一个CLI命令,该命令在存储桶内制作文件夹的递归副本,并将ACL设置为“ Buckesl所有者完全控制”。 局部函数正确运行。 但是我需要在AWS控制台中进行测试才能提高生产环境。 在Lambda服务中使用以下代码进行测试时:

import boto3

def lambda_handler(event, context):

    subprocess.call(['aws', 's3', 'cp', '--recursive', '--acl', 'bucket-owner-full-control', 's3://bucket1/db1', 's3://bucket1/db1'], shell=True)

我只会得到响应= null ,而我想要的更改不会发生在存储桶内(什么都没发生)。

是否可以在AWS Lambda内运行此子过程模块?

这是AWS控制台中响应的打印:

“

I need to run a CLI command that makes a recursive copy of folders inside a bucket and sets the ACL as "bucket owner full control".
Locally the function ran correctly.
But I need to test in the AWS console to go up to productive environment.
When testing in lambda service with the following code:

import boto3

def lambda_handler(event, context):

    subprocess.call(['aws', 's3', 'cp', '--recursive', '--acl', 'bucket-owner-full-control', 's3://bucket1/db1', 's3://bucket1/db1'], shell=True)

I just get a response = null and the change I want doesn't happen inside the bucket (nothing happens).

Is it possible to run this subprocess module inside AWS Lambda?

This is the print of response in AWS console:

Image of respose

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

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

发布评论

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

评论(1

莫多说 2025-02-13 09:13:14

您的lambda_handler不会返回任何内容。您必须向处理程序添加返回语句。

但是,即使您这样做也行不通,因为Lambda没有AWS CLI。您应该使用 aws boto3 与您的lambda中的s3互动。

Your lambda_handler does not return anything. You have to add return statement to your handler.

But even if you do it will not work, as lambda does not have AWS CLI. You should be using AWS boto3 to interact with S3 in your lambda.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文