要解决AWS CloudWatch Events不会触发Lambda函数的问题,需要确保以下几个方面:
aws events put-rule --name my-rule --event-pattern "{\"source\":[\"aws.ec2\"],\"detail-type\":[\"EC2 Instance State-change Notification\"]}"
aws events put-targets --rule my-rule --targets "Id"="1","Arn"="arn:aws:lambda:us-east-1:123456789012:function:my-function"
aws iam attach-role-policy --role-name my-lambda-role --policy-arn arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
import json
def lambda_handler(event, context):
print("Received event: " + json.dumps(event))
通过检查上述方面,您应该能够解决AWS CloudWatch Events不触发Lambda函数的问题。