简体   繁体   English

AWS lambda function 使用 python 删除 s3 存储桶的内容

[英]AWS lambda function to delete contents of s3 bucket using python

How do I write lambda function in AWS(python) to delete the contents of S3 buckets.如何在 AWS(python) 中编写 lambda function 以删除 S3 存储桶的内容。 please share the template on this regard I just want the codes.请分享这方面的模板,我只想要代码。

This will help you in setting up a Python based lambda - including entry point for handler: https://stackify.com/aws-lambda-with-python-a-complete-getting-started-guide/这将帮助您设置基于 Python 的 lambda - 包括处理程序的入口点: https/stackify -complete-getting-lambda-with-python

Once that is figured out, you need to create an s3 client using:一旦弄清楚了,您需要使用以下命令创建一个 s3 客户端:

import boto3
client = boto3.client("s3")

Then you can follow the user guide to empty bucket: https://docs.aws.amazon.com/AmazonS3/latest/userguide/empty-bucket.html然后您可以按照用户指南清空存储桶: https://docs.aws.amazon.com/AmazonS3/latest/userguide/empty-bucket.html

Also note that the lambda is run using an assumed role, please make sure the IAM role has relevant permissions: https://docs.aws.amazon.com/lambda/latest/dg/lambda-intro-execution-role.html另请注意,lambda 使用假定角色运行,请确保 IAM 角色具有相关权限: https://docs.aws.amazon.com/lambda/latest/dg/lambda-intro-execution-role.C7235FDC87082EFC

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM