Got a problem…trying to create a trigger on a Lambda with a Resource I’m creating in the resources
section. I’m using this trigger multiple times, so I don’t want to create it using the inherent method in Serverless Framework.
The CW Rule shows that it’s supposed to trigger the lambda. When you go to the Lambda, that trigger isn’t actually getting applied.
Could someone please look at the code and advice any modifications to get it to work?
Thanks!
functions:
EventMonitor:
handler: event_monitor.handle_event
environment:
CF_StateMachine: arn:aws:states:${opt:region}:${self:custom.commonVariables.us}:stateMachine:ScannerDeploy
events:
- cloudwatchEvent:
arn:
Fn::GetAtt:
- EC2RunInstancesTriggerRule
- Arn
resource:
Resources:
EC2RunInstancesTriggerRule:
Type: "AWS::Events::Rule"
Properties:
Name: ${self:service}-EC2RunInstancesTrigger
Description: "Triggers StateMachine:cannerDeploy upon CW Event: RunInstances"
State: ENABLED
EventPattern:
source:
- aws.ec2
detail-type:
- AWS API Call via CloudTrail
detail:
eventSource:
- ec2.amazonaws.com
eventName:
- RunInstances
Targets:
-
Arn:
Fn::GetAtt:
- EventMonitorLambdaFunction
- Arn
Id: "EventMonitor"