This repository has been archived by the owner on Jun 27, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
131 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
'use strict'; | ||
var Generator = require('yeoman-generator'); | ||
var chalk = require('chalk'); | ||
var yosay = require('yosay'); | ||
|
||
module.exports = Generator.extend({ | ||
prompting: function () { | ||
this.log(yosay( | ||
'Welcome to the terrific ' + chalk.red('generator-cloudformation') + ' generator for scheduled lambdas!' | ||
)); | ||
|
||
var prompts = [{ | ||
type: 'input', | ||
name: 'description', | ||
message: 'The description of the lambda?' | ||
}, { | ||
type: 'input', | ||
name: 'expression', | ||
message: 'The schedule expression?', | ||
default: 'rate(1 day)' | ||
}, { | ||
type: 'input', | ||
name: 'timeout', | ||
message: 'The lambda execution timeout in seconds?', | ||
default: '30' | ||
}]; | ||
|
||
return this.prompt(prompts).then(function (props) { | ||
this.props = props; | ||
}.bind(this)); | ||
}, | ||
|
||
writing: function () { | ||
this.fs.copyTpl( | ||
this.templatePath('cfn.yaml'), | ||
this.destinationPath('cfn.yaml'), | ||
this.props | ||
); | ||
}, | ||
|
||
install: function () { | ||
// | ||
} | ||
}); |
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,61 @@ | ||
AWSTemplateFormatVersion: '2010-09-09' | ||
Description: '<%= description %>' | ||
Resources: | ||
FunctionRole: | ||
Type: 'AWS::IAM::Role' | ||
Properties: | ||
AssumeRolePolicyDocument: | ||
Version: '2012-10-17' | ||
Statement: | ||
- Effect: Allow | ||
Principal: | ||
Service: | ||
- lambda.amazonaws.com | ||
Action: 'sts:AssumeRole' | ||
Path: / | ||
Policies: | ||
- PolicyName: root | ||
PolicyDocument: | ||
Version: '2012-10-17' | ||
Statement: | ||
# TODO Insert needed permissions here | ||
- Effect: Allow | ||
Action: | ||
- 'logs:CreateLogGroup' | ||
- 'logs:CreateLogStream' | ||
- 'logs:PutLogEvents' | ||
Resource: 'arn:aws:logs:*:*:*' | ||
Function: | ||
Type: 'AWS::Lambda::Function' | ||
Properties: | ||
Handler: index.handler | ||
Role: !GetAtt FunctionRole.Arn | ||
Code: | ||
ZipFile: !Sub | | ||
"use strict"; | ||
var AWS = require('aws-sdk'); | ||
exports.handler = function (event, context, callback) { | ||
CallSomePromiseHere.then(function () { | ||
callback(null, 'Successfully finished'); | ||
}).catch(function (err) { | ||
callback(err); | ||
}); | ||
}; | ||
Runtime: nodejs4.3 | ||
Timeout: '<%= timeout %>' | ||
CronRule: | ||
Type: 'AWS::Events::Rule' | ||
Properties: | ||
ScheduleExpression: '<%= expression %>' | ||
Targets: | ||
- Id: LambdaScheduler | ||
Arn: !GetAtt Function.Arn | ||
InvokeLambdaPermission: | ||
Type: 'AWS::Lambda::Permission' | ||
Properties: | ||
FunctionName: !GetAtt Function.Arn | ||
Action: 'lambda:InvokeFunction' | ||
Principal: events.amazonaws.com | ||
SourceArn: !GetAtt CronRule.Arn |
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,18 @@ | ||
'use strict'; | ||
var path = require('path'); | ||
var assert = require('yeoman-assert'); | ||
var helpers = require('yeoman-test'); | ||
|
||
describe('generator-cloudformation:cronjob', function () { | ||
before(function () { | ||
return helpers.run(path.join(__dirname, '../generators/cronjob')) | ||
.withPrompts({someAnswer: true}) | ||
.toPromise(); | ||
}); | ||
|
||
it('creates files', function () { | ||
assert.file([ | ||
'cfn.yaml' | ||
]); | ||
}); | ||
}); |