0
我想用无服务器应用模型(SAM)和CloudFormation创建时,在S3存储桶(例如thescore-cloudfront-trial
)创建一个对象,它被触发一个简单的lambda函数。如何启用S3存储区到Lambda函数的触发器?以下是我的python3 boto3代码。AWS无服务器应用模式:创建S3事件与λ
region = 'us-east-1'
import boto3
test_lambda_template = {
'AWSTemplateFormatVersion': '2010-09-09',
'Transform': 'AWS::Serverless-2016-10-31',
'Resources': {
'CopyS3RajivCloudF': {
'Type': 'AWS::Serverless::Function',
'Properties': {
"CodeUri": 's3://my-tmp/CopyS3Lambda',
"Handler": 'lambda.handler',
"Runtime": 'python3.6',
"Timeout": 300,
"Role": 'my_existing_role_arn'
},
'Events': {
'Type': 'S3',
'Properties': {
"Bucket": "thescore-cloudfront-trial",
"Events": 's3:ObjectCreated:*'
}
}
},
'SrcBucket': {
"Type": "AWS::S3::Bucket",
"Properties": {
"BucketName": 'thescore-cloudfront-trial',
}
}
}
}
conf = config.get_aws_config('development')
client = aws.client(conf, 'cloudformation', region_name=region)
response = client.create_change_set(
StackName='RajivTestStack',
TemplateBody=json.dumps(test_lambda_template),
Capabilities=['CAPABILITY_IAM'],
ChangeSetName='a',
Description='Rajiv ChangeSet Description',
ChangeSetType='CREATE'
)
response = client.execute_change_set(
ChangeSetName='a',
StackName='RajivTestStack',
)
你有没有考虑阅读[文档](http://docs.aws.amazon.com/lambda/latest/dg/with-s3.html)? – stdunbar
1.使用AWS控制台在您的S3存储桶中添加一个触发器。 2.使用boto3添加您的活动:http://boto3.readthedocs.io/en/latest/reference/services/s3.html#S3.Client.put_bucket_notification_configuration – mootmoot
@mootmoot:我已经有Python脚本你做什么所列: )。我想转移到SAM。 – RAbraham