Amazon web services 在我的IaC堆栈中获取自动存储桶策略的处理程序错误
我检查了lambda控制台,查看是否在其中写入了我的函数,并得到如下错误消息: “Lambda找不到文件Lambda_handler.py。请确保处理程序支持以下格式:file name.method。”Amazon web services 在我的IaC堆栈中获取自动存储桶策略的处理程序错误,amazon-web-services,amazon-s3,amazon-cloudformation,Amazon Web Services,Amazon S3,Amazon Cloudformation,我检查了lambda控制台,查看是否在其中写入了我的函数,并得到如下错误消息: “Lambda找不到文件Lambda_handler.py。请确保处理程序支持以下格式:file name.method。” 我的处理程序名为lambda_handler.py,那么为什么现在还不能工作呢?创建的文件名为index.py 因此,Handler属性将是index.lambda\u Handler。这是因为处理程序定义了与Lambda服务调用的函数组合的文件名 如上所述,该文件是index.py,但Lam
我的处理程序名为lambda_handler.py,那么为什么现在还不能工作呢?创建的文件名为
index.py
因此,Handler
属性将是index.lambda\u Handler
。这是因为处理程序定义了与Lambda服务调用的函数组合的文件名
如上所述,该文件是index.py
,但Lambda知道您的运行时,它只需要文件名的索引部分,那么代码中定义的函数是Lambda\u handler
更新处理程序值,这应该会起作用。没问题,祝您愉快:)
AWSTemplateFormatVersion: '2010-09-09'
Resources:
LambdaFunction:
Type: 'AWS::Lambda::Function'
Properties:
Code:
ZipFile: |
import json
import boto3
s3 = boto3.client('s3')
def lambda_handler(event, context):
# Get bucket name from the S3 event
print(event)
bucket_name = event['detail']['requestParameters']['bucketName']
# Create a bucket policy
bucket_policy =json.dumps({
"Version": "2012-10-17",
"Statement": [
{
"Sid": "MustBeEncryptedAtRest",
"Effect": "Deny",
"Principal": "*",
"Action": "s3:PutObject",
"Resource": [
"arn:aws:s3:::{}".format(bucket_name),
"arn:aws:s3:::{}/*".format(bucket_name)
],
"Condition": {
"StringNotEquals": {
"s3:x-amz-server-side-encryption": [
AES256
"aws:kms"
]
}
}
},
{
"Sid": "MustBeEncryptedInTransit",
"Effect": "Deny",
"Principal": "*",
"Action": "s3:*",
"Resource": [
"arn:aws:s3:::{}".format(bucket_name),
"arn:aws:s3:::{}/*".format(bucket_name)
],
"Condition": {
"Bool": {
"aws:SecureTransport": "false"
}
}
} ] })
# Set the new policy
s3.put_bucket_policy(Bucket=bucket_name, Policy=bucket_policy),
Handler: lambda_handler.py
Role: 'arn:aws:iam::myrole'
Runtime: python3.7
EventRule:
Type: 'AWS::Events::Rule'
Properties:
EventPattern:
source:
- aws.s3
detail-type:
- AWS API Call via CloudTrail
detail:
eventSource:
- s3.amazonaws.com
eventName:
- CreateBucket