Ich habe bereits meine Lambda/Rollen in cloudformation definiert und würde es gerne verwenden, um eine geplante eventsources hinzuzufügen ... gibt es irgendwelche Dokumente oder Beispiele?AWS Lambda geplante Ereignisquelle über cloudformation
Antwort
Verwenden Aws::Event::Rule mit einem ScheduleExpression
und ein AWS::Lambda::Permission
// rule to periodically call the lambda
"TagWatcherRule": {
"Type": "AWS::Events::Rule",
"Properties": {
"ScheduleExpression": "rate(10 minutes)",
"Targets": [
{
"Id": "TagWatcherScheduler",
"Arn": {
"Fn::GetAtt": [
"TagWatcherFunction",
"Arn"
]
}
}
]
}
},
// role may call the lambda
"InvokeLambdaPermission": {
"Type": "AWS::Lambda::Permission",
"Properties": {
"FunctionName": {
"Fn::GetAtt": [
"TagWatcherFunction",
"Arn"
]
},
"Action": "lambda:InvokeFunction",
"Principal": "events.amazonaws.com",
"SourceArn": {
"Fn::GetAtt": [
"TagWatcherRule",
"Arn"
]
}
}
}
Leider wird das Konfigurieren geplanter Ereignisquellen für Lambda-Funktionen derzeit von CloudFormation nicht unterstützt. Sie müssen Ihr Lambda mithilfe von CloudFormation bereitstellen und dann Ihre geplanten Ereignisse manuell konfigurieren.
CloudFormation unterstützt einen Ressourcentyp AWS::Lambda::EventSourceMapping
. Diese Ressource ist jedoch nur eingeschränkt in der Lage, Kinesis- oder DynamoDB-Streams zu konfigurieren, daher ist dies für Sie wahrscheinlich nicht hilfreich.
** Update - ab April 2016 wird diese nun unterstützt mit Cloudwatch Events - https://aws.amazon.com/about-aws/whats-new/2016/04/amazon-cloudwatch-events-now-supported-in-aws-cloudformation-templates/
Ab dieser Woche (18. April 2016) ist es nun möglich, ein hinzufügen Geplante CloudWatch-Ereignisregel, die Ihre Lambda-Funktion auslöst.
Die AWS::Event::Rule hat eine ScheduleExpression
Feld für den cron-style Zeitplan und eine Targets
Array, die eine Lambda-Funktion ARN annehmen kann.
ich gleiches Problem gelöst.
"RoleForLambdaStopEC2Instances" : {
"Type": "AWS::IAM::Role",
"Properties": {
"AssumeRolePolicyDocument": {
"Version": "2012-10-17",
"Statement": [
{
"Sid": "",
"Effect": "Allow",
"Principal": {
"Service": "lambda.amazonaws.com"
},
"Action": "sts:AssumeRole"
}
]
},
"Policies": [
{
"PolicyName": "LambdaStopEC2InstancesPolicy",
"PolicyDocument": {
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents",
"ec2:StopInstances"
],
"Resource": [
"arn:aws:logs:*:*:*",
"arn:aws:ec2:*"
]
}
]
}
}
],
"Path": "/"
}
},
"LambdaStopEC2Instances": {
"Type": "AWS::Lambda::Function",
"Properties": {
"Code": {
"S3Bucket": "XXXXXXXXXXXXXXXXX",
"S3Key": "XXXXXXXXXXXXXXXXXX"
},
"Handler": "stopEC2Instances.handler",
"Role": { "Fn::GetAtt" : ["RoleForLambdaStopEC2Instances", "Arn"] },
"Runtime": "nodejs4.3",
"Timeout": "5"
}
},
"StopEC2InstancesRule": {
"Type" : "AWS::Events::Rule",
"Properties" : {
"Name" : "StopEC2Instances",
"ScheduleExpression" : "cron(0 13 ? * MON-FRI *)",
"State": "ENABLED",
"Targets": [{
"Arn": { "Fn::GetAtt": ["LambdaStopEC2Instances", "Arn"] },
"Id": "stopEC2Instances"
}]
}
},
"LambdaInvokePermission": {
"Type": "AWS::Lambda::Permission",
"Properties": {
"FunctionName" : { "Fn::GetAtt" : ["LambdaStopEC2Instances", "Arn"] },
"Action": "lambda:InvokeFunction",
"Principal": "events.amazonaws.com",
"SourceAccount": { "Ref" : "AWS::AccountId" },
"SourceArn": { "Fn::GetAtt": ["StopEC2InstancesRule","Arn"] }
}
}
AWS supports periodic run through sourcedetails.
EventSource: "aws.config"
MaximumExecutionFrequency: Twelve_Hours
MessageType: "ScheduledNotification"
- 1. AWS Lambda S3-Bucket-Benachrichtigung über CloudFormation
- 2. Zugriff AWS CloudFormation ARN von innen Lambda-Funktion
- 3. AWS CloudFormation benutzerdefinierte Lambda-Funktion stecken im create-Status
- 4. AWS cloudformation optionale Zeile
- 5. Verwalten der Lambda-Handler Anmeldeinformationen in Cloudformation
- 6. AWS Lambda - CloudWatch Ereignistyp
- 7. AWS :: CloudFormation :: Init wie funktioniert es?
- 8. Return JSONP über AWS Lambda/API-Gateway
- 9. aws CloudFormation AWS :: EC2 :: Instanz BlockDeviceMappings und Volumes
- 10. AWS-Ressourcen mit CloudFormation-Vorlagen validieren
- 11. AWS CloudFormation Problem mit VPC und Subnet
- 12. AWS Lambda und MongoDB
- 13. Möglich, geplante .exe auf aws auszuführen?
- 14. AWS Lambda NoClassDefFoundError
- 15. Anruf aws-cli von AWS Lambda
- 16. AWS Lambda Throughput
- 17. AWS Lambda Logging Error
- 18. AWS SNS als Quelle für AWS Lambda
- 19. Wie richtet man Parse Server mit MongoDB über CloudFormation ein?
- 20. AWS Lambda-Image beschädigt
- 21. AWS Lambda: org.apache.http.conn.ConnectTimeoutException
- 22. AWS Lambda S3Event-Deserialisierung
- 23. Pandas & AWS Lambda
- 24. AWS Lambda Dynamischer Endpunkt
- 25. Python Pusher AWS Lambda
- 26. AWS Lambda Java Kompatiblität
- 27. Mocking in AWS Lambda
- 28. AWS Lambda TooManyRequestsException: Rate
- 29. Ein AWS Lambda anhören
- 30. AWS Lambda + Python-ldap
Laut den Dokumenten muss ScheduleExpression mehrere Minuten nicht Minute sein. http://docs.aws.amazon.com/AmazonCloudWatch/latest/DeveloperGuide/ScheduledEvents.html –
@ timmah.faase Nicht wahr? "Gültige Werte: Minute | Minuten | Stunde | Stunden | Tag | Tage" – dsvensson
Sie dürfen Singular auf "1", z. "1 Minute", muss jedoch im Plural verwendet werden, z. "10 Minuten". Grammatik wird durchgesetzt! – helloPiers