-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
CloudWatch Events Resource/Property #467
Merged
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
0f2a3e9
Added CWEvents (Events) support
e81945f
removed unneeded imports
c5b84e2
changed name of example
dfa3d29
fixed test due to example output being wrong
c8a03e2
slimmed down the test
4a4873e
slimmed down the test
08f6108
Removed unused imports
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
from troposphere import Template | ||
from troposphere.events import Rule, Target | ||
from troposphere.iam import Role, Policy | ||
from troposphere.awslambda import Function, Code | ||
from troposphere import GetAtt, Join | ||
|
||
|
||
t = Template() | ||
|
||
|
||
# Create a Lambda function that will be mapped | ||
code = [ | ||
"var response = require('cfn-response');", | ||
"exports.handler = function(event, context) {", | ||
" context.succeed('foobar!');", | ||
" return 'foobar!';", | ||
"};", | ||
] | ||
|
||
# Create a role for the lambda function | ||
t.add_resource(Role( | ||
"LambdaExecutionRole", | ||
Path="/", | ||
Policies=[Policy( | ||
PolicyName="root", | ||
PolicyDocument={ | ||
"Version": "2012-10-17", | ||
"Statement": [{ | ||
"Action": ["logs:*"], | ||
"Resource": "arn:aws:logs:*:*:*", | ||
"Effect": "Allow" | ||
}, { | ||
"Action": ["lambda:*"], | ||
"Resource": "*", | ||
"Effect": "Allow" | ||
}] | ||
})], | ||
AssumeRolePolicyDocument={"Version": "2012-10-17", "Statement": [ | ||
{ | ||
"Action": ["sts:AssumeRole"], | ||
"Effect": "Allow", | ||
"Principal": { | ||
"Service": [ | ||
"lambda.amazonaws.com", | ||
"apigateway.amazonaws.com" | ||
] | ||
} | ||
} | ||
]}, | ||
)) | ||
|
||
# Create the Lambda function | ||
foobar_function = t.add_resource(Function( | ||
"FoobarFunction", | ||
Code=Code( | ||
ZipFile=Join("", code) | ||
), | ||
Handler="index.handler", | ||
Role=GetAtt("LambdaExecutionRole", "Arn"), | ||
Runtime="nodejs", | ||
)) | ||
|
||
# Create the Event Target | ||
foobar_target = Target( | ||
"FoobarTarget", | ||
Arn=GetAtt('FoobarFunction', 'Arn'), | ||
Id="FooBarFunction1" | ||
) | ||
|
||
# Create the Event Rule | ||
rule = Rule( | ||
"FoobarRule", | ||
EventPattern={ | ||
"source": [ | ||
"aws.ec2" | ||
], | ||
"detail-type": [ | ||
"EC2 Instance State-change Notification" | ||
], | ||
"detail": { | ||
"state": [ | ||
"stopping" | ||
] | ||
} | ||
}, | ||
Description="Foobar CloudWatch Event", | ||
State="ENABLED", | ||
Targets=[foobar_target] | ||
) | ||
|
||
print(t.to_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,79 @@ | ||
{'Source': ([<type 'basestring'>], True), 'Detail': (<type 'dict'>, True), 'DetailType': ([<type 'basestring'>], True)} | ||
{ | ||
"Resources": { | ||
"FoobarFunction": { | ||
"Properties": { | ||
"Code": { | ||
"ZipFile": { | ||
"Fn::Join": [ | ||
"", | ||
[ | ||
"var response = require('cfn-response');", | ||
"exports.handler = function(event, context) {", | ||
" context.succeed('foobar!');", | ||
" return 'foobar!';", | ||
"};" | ||
] | ||
] | ||
} | ||
}, | ||
"Handler": "index.handler", | ||
"Role": { | ||
"Fn::GetAtt": [ | ||
"LambdaExecutionRole", | ||
"Arn" | ||
] | ||
}, | ||
"Runtime": "nodejs" | ||
}, | ||
"Type": "AWS::Lambda::Function" | ||
}, | ||
"LambdaExecutionRole": { | ||
"Properties": { | ||
"AssumeRolePolicyDocument": { | ||
"Statement": [ | ||
{ | ||
"Action": [ | ||
"sts:AssumeRole" | ||
], | ||
"Effect": "Allow", | ||
"Principal": { | ||
"Service": [ | ||
"lambda.amazonaws.com", | ||
"apigateway.amazonaws.com" | ||
] | ||
} | ||
} | ||
], | ||
"Version": "2012-10-17" | ||
}, | ||
"Path": "/", | ||
"Policies": [ | ||
{ | ||
"PolicyDocument": { | ||
"Statement": [ | ||
{ | ||
"Action": [ | ||
"logs:*" | ||
], | ||
"Effect": "Allow", | ||
"Resource": "arn:aws:logs:*:*:*" | ||
}, | ||
{ | ||
"Action": [ | ||
"lambda:*" | ||
], | ||
"Effect": "Allow", | ||
"Resource": "*" | ||
} | ||
], | ||
"Version": "2012-10-17" | ||
}, | ||
"PolicyName": "root" | ||
} | ||
] | ||
}, | ||
"Type": "AWS::IAM::Role" | ||
} | ||
} | ||
} |
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,33 @@ | ||
# Copyright (c) 2013, Mark Peek <mark@peek.org> | ||
# All rights reserved. | ||
# | ||
# See LICENSE file for full license. | ||
|
||
from . import AWSObject, AWSProperty, Ref | ||
from .validators import positive_integer, boolean | ||
|
||
class Target(AWSProperty): | ||
|
||
props = { | ||
'Arn': (basestring, True), | ||
'Id': (basestring, True), | ||
'Input': (basestring, False), | ||
'InputPath': (basestring, False) | ||
|
||
} | ||
|
||
|
||
class Rule(AWSObject): | ||
resource_type = "AWS::Events::Rule" | ||
|
||
props = { | ||
|
||
'Description': (basestring, False), | ||
'EventPattern': (dict, False), | ||
'Name': (basestring, False), | ||
'RoleArn': (basestring, False), | ||
'ScheduleExpression': (basestring, False), | ||
'State': (basestring, False), | ||
'Targets': ([Target], False) | ||
|
||
} |
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.
You don't need this one ;)
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.
haha thanks - i haven't contributed to this before so used your PR as a guide :)
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.
Me neither ;)
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.
well i guess good luck to both of us 👍