-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Lambda: Fix CloudWatch event rule permissions #558
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
132 changes: 132 additions & 0 deletions
132
packages/@aws-cdk/aws-lambda/test/integ.events.expected.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
{ | ||
"Resources": { | ||
"MyFuncServiceRole54065130": { | ||
"Type": "AWS::IAM::Role", | ||
"Properties": { | ||
"AssumeRolePolicyDocument": { | ||
"Statement": [ | ||
{ | ||
"Action": "sts:AssumeRole", | ||
"Effect": "Allow", | ||
"Principal": { | ||
"Service": "lambda.amazonaws.com" | ||
} | ||
} | ||
], | ||
"Version": "2012-10-17" | ||
}, | ||
"ManagedPolicyArns": [ | ||
{ | ||
"Fn::Join": [ | ||
"", | ||
[ | ||
"arn", | ||
":", | ||
{ | ||
"Ref": "AWS::Partition" | ||
}, | ||
":", | ||
"iam", | ||
":", | ||
"", | ||
":", | ||
"aws", | ||
":", | ||
"policy", | ||
"/", | ||
"service-role/AWSLambdaBasicExecutionRole" | ||
] | ||
] | ||
} | ||
] | ||
} | ||
}, | ||
"MyFunc8A243A2C": { | ||
"Type": "AWS::Lambda::Function", | ||
"Properties": { | ||
"Code": { | ||
"ZipFile": "exports.handler = function handler(event, _context, callback) {\n console.log(JSON.stringify(event, undefined, 2));\n return callback();\n}" | ||
}, | ||
"Handler": "index.handler", | ||
"Role": { | ||
"Fn::GetAtt": [ | ||
"MyFuncServiceRole54065130", | ||
"Arn" | ||
] | ||
}, | ||
"Runtime": "nodejs6.10" | ||
}, | ||
"DependsOn": [ | ||
"MyFuncServiceRole54065130" | ||
] | ||
}, | ||
"MyFuncAllowEventRulelambdaeventsTimer0E6AB6D8E3B334A3": { | ||
"Type": "AWS::Lambda::Permission", | ||
"Properties": { | ||
"Action": "lambda:InvokeFunction", | ||
"FunctionName": { | ||
"Ref": "MyFunc8A243A2C" | ||
}, | ||
"Principal": "events.amazonaws.com", | ||
"SourceArn": { | ||
"Fn::GetAtt": [ | ||
"TimerBF6F831F", | ||
"Arn" | ||
] | ||
} | ||
} | ||
}, | ||
"MyFuncAllowEventRulelambdaeventsTimer27F866A1E0669C645": { | ||
"Type": "AWS::Lambda::Permission", | ||
"Properties": { | ||
"Action": "lambda:InvokeFunction", | ||
"FunctionName": { | ||
"Ref": "MyFunc8A243A2C" | ||
}, | ||
"Principal": "events.amazonaws.com", | ||
"SourceArn": { | ||
"Fn::GetAtt": [ | ||
"Timer2B6F162E9", | ||
"Arn" | ||
] | ||
} | ||
} | ||
}, | ||
"TimerBF6F831F": { | ||
"Type": "AWS::Events::Rule", | ||
"Properties": { | ||
"ScheduleExpression": "rate(1 minute)", | ||
"State": "ENABLED", | ||
"Targets": [ | ||
{ | ||
"Arn": { | ||
"Fn::GetAtt": [ | ||
"MyFunc8A243A2C", | ||
"Arn" | ||
] | ||
}, | ||
"Id": "MyFunc" | ||
} | ||
] | ||
} | ||
}, | ||
"Timer2B6F162E9": { | ||
"Type": "AWS::Events::Rule", | ||
"Properties": { | ||
"ScheduleExpression": "rate(2 minutes)", | ||
"State": "ENABLED", | ||
"Targets": [ | ||
{ | ||
"Arn": { | ||
"Fn::GetAtt": [ | ||
"MyFunc8A243A2C", | ||
"Arn" | ||
] | ||
}, | ||
"Id": "MyFunc" | ||
} | ||
] | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import events = require('@aws-cdk/aws-events'); | ||
import cdk = require('@aws-cdk/cdk'); | ||
import lambda = require('../lib'); | ||
|
||
const app = new cdk.App(process.argv); | ||
|
||
const stack = new cdk.Stack(app, 'lambda-events'); | ||
|
||
const fn = new lambda.Function(stack, 'MyFunc', { | ||
runtime: lambda.Runtime.NodeJS610, | ||
handler: 'index.handler', | ||
code: lambda.Code.inline(`exports.handler = ${handler.toString()}`) | ||
}); | ||
|
||
const timer = new events.EventRule(stack, 'Timer', { scheduleExpression: 'rate(1 minute)' }); | ||
timer.addTarget(fn); | ||
|
||
const timer2 = new events.EventRule(stack, 'Timer2', { scheduleExpression: 'rate(2 minutes)' }); | ||
timer2.addTarget(fn); | ||
|
||
process.stdout.write(app.run()); | ||
|
||
// tslint:disable:no-console | ||
function handler(event: any, _context: any, callback: any) { | ||
console.log(JSON.stringify(event, undefined, 2)); | ||
return callback(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -123,4 +123,4 @@ | |
] | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe nicer to pass the
Rule
itself, no?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a good chance we would want to extract
IEventRuleTarget
into a separate module to prevent cyclic references (which is what I am doing with bucket notifications), so I am trying to standardize on a low-level signature for event targets, and this is the same signature asIBucketNotificationDestination
will have.