Reputation: 13
I am tasked to write a lambda function that would enable versioning on multiple S3 buckets. How would I do this?
Upvotes: 1
Views: 486
Reputation: 1948
The below lambda code in python v3.8 will enable versioning for all S3 buckets in your account.
import json
import boto3
def lambda_handler(event, context):
s3 = boto3.client('s3')
response = s3.list_buckets()
for bucket in response['Buckets']:
s3.put_bucket_versioning(Bucket=bucket["Name"],
VersioningConfiguration={
'MFADelete': 'Disabled',
'Status': 'Enabled',
},
)
print("Enabled versioning on bucket : ", bucket["Name"])
return {
'statusCode': 200,
'body': json.dumps('Hello from Lambda!')
}
For more details, please refer to the AWS SDK for Python (Boto3) here.
Upvotes: 1
Reputation: 21
You can use serverless for backend. And you can deploy it to S3 buckets and AWS Lambda functions.
serverless deploy
You can reference more details here
Upvotes: 0