lambit 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 015317ec388f92657fdfd9aae8dee01667f50c26
4
+ data.tar.gz: 514f02781d641b0250e2912154fb2fd5f1f81400
5
+ SHA512:
6
+ metadata.gz: ac0c223092e97287c99df528addb2bec486ca569944fda6911de0cf3e89073de3b24bd307c663b20ccb5017e9e032eb33fe42736dcc4c1b7815ace881ac9e0e6
7
+ data.tar.gz: 48d570c9b1a344f2aca3d3f030795e2bbc0e6f90aa82fa54c9f5e339ef969904211803fdd57b156012b2a2b3559994f641a28e7a8313ea13301781410c71404a
@@ -0,0 +1 @@
1
+ PATH_add bin
@@ -0,0 +1,18 @@
1
+ .DS_Store
2
+ .bundle/
3
+ *.swp
4
+ *.swo
5
+ .idea
6
+ ~*
7
+ log/*
8
+ tmp/*
9
+ vendor/bundle
10
+ .tags
11
+ .gemtags
12
+ ctags*
13
+ *.sublime-*
14
+ *.gem
15
+ .envrc
16
+ .ruby-version
17
+ bin/*
18
+ !bin/lambit
@@ -0,0 +1 @@
1
+ 2.2.4
File without changes
@@ -0,0 +1,7 @@
1
+ Lambit Changelog
2
+ ===
3
+
4
+ 0.0.1
5
+ ---
6
+ - Initial release
7
+ - TODO: Replace eval statements with limited parser
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source 'https://rubygems.org'
2
+
3
+ group :development do
4
+ gem 'pry', '~> 0.10.0'
5
+ end
6
+
7
+ group :test do
8
+ gem 'rake', '~> 10.4.0'
9
+ gem 'mocha', '~> 1.1.0'
10
+ gem 'shoulda-context', '~> 1.2.0'
11
+ end
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Will Drew
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,74 @@
1
+ lambit
2
+ ========
3
+
4
+ A utility to manage AWS Lambda Service. Lambda + It => Lambit!
5
+
6
+ This tool programmatically manages AWS Lambdas including various Event Sources using Lambit project conventions and a yaml configuration file. It also has the ability to associate alarms based on metrics produced.
7
+
8
+
9
+ ## Prerequisites
10
+ - AWS properly configured on machine for SDK/CLI
11
+
12
+
13
+ ## Shell Environment Variables
14
+ - $AWS_REGION
15
+ * Required
16
+ - $AWS_ACCESS_KEY
17
+ * Optional
18
+ - $AWS_SECRET_KEY
19
+ * Optional
20
+ - $LAMBIT_PROJECT_PATH
21
+ * Required path to Lambit project
22
+ - $LAMBIT_CONFIG_FILENAME
23
+ * The config filename for Lambit
24
+ * Defaults to 'lambit.yml'
25
+ - $LAMBIT_REGEXP
26
+ * The filter regexp to filter Lambda Function(s)
27
+ * Default is nil and processes all project Lambdas
28
+
29
+
30
+ ## Lambit Commands
31
+ - build
32
+ * Builds Lambda Function deploy packages for deployment for Lambit project Lambda(s)
33
+ - deploy
34
+ * Deploys (creates AWS Lambda Functions) for project Lambda(s) using built Lambda Function deploy packages
35
+ - delete
36
+ * Deletes the AWS Lambda Functions for the project Lambda(s)
37
+ - add_event_sources
38
+ * Adds Event Sources to the AWS Lambda Functions for the project Lambda(s)
39
+ - remove_event_sources
40
+ * Removes Event Sources from the AWS Lambda Functions for the project Lambda(s)
41
+ - add_alarms
42
+ * Adds CloudWatch Alarms to the AWS Lambda Functions for the project Lambda(s)
43
+ - delete_alarms
44
+ * Deletes CloudWatch Alarms from the AWS Lambda Functions for the project Lambda(s)
45
+
46
+
47
+ ### Example Usages
48
+ ``` shell
49
+ lambit build
50
+ lambit deploy
51
+ lambit add_event_sources
52
+ lambit add_alarms
53
+ ```
54
+
55
+ ## Lambit Project Conventions
56
+
57
+ ``` shell
58
+ ./lambdas
59
+ ./my-lambit-project
60
+ ./function
61
+ ./templates
62
+ .lambit.yml
63
+ ./my-other-lambit-project
64
+ ...
65
+ ``` shell
66
+
67
+ - 'function' directory should contain any function code (required)
68
+ - 'templates' directory should contain any templates like .json files (optional)
69
+ - 'lambit.yml' configuration file for Lambit project, please look at example 'lambit.yml.example'
70
+ - Relevant section values conform to aws-sdk expected hashes, refer to the 'aws-sdk' for rb for details
71
+ - Python Lambda Functions are able to install 'required_pips' for deployable packages
72
+ - Advanced: Sprinkle of built-in magic that provides support for fetching function names and indexes (subject to change)
73
+
74
+ Credit [Ethan Rowe ](https://github.com/ethanrowe) for the original command handler technique in [hadupils](https://github.com/ethanrowe/hadupils).
File without changes
@@ -0,0 +1,91 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # vim: set filetype=ruby:
4
+
5
+ require 'gli'
6
+ require 'lambit'
7
+
8
+ include GLI::App
9
+
10
+ version Lambit::VERSION
11
+
12
+ program_desc 'A utility to manage AWS Lambda. Lambda + It => Lambit!'
13
+
14
+ tmpdir = ENV['LAMBIT_TMPDIR']
15
+ project_path = ENV['LAMBIT_PROJECT_PATH']
16
+ config_filename = ENV['LAMBIT_CONFIG_FILENAME']
17
+ regexp = ENV['LAMBIT_REGEXP']
18
+
19
+ flag ['tmpdir'], :default_value => tmpdir || '/tmp/lambit'
20
+ flag ['config-filename'], :default_value => config_filename || 'lambit.yml'
21
+ flag ['project-path'], :default_value => project_path
22
+ flag ['regexp'], :default_value => regexp
23
+
24
+ switch [:d, 'debug']
25
+ switch [:v, 'verbose']
26
+ switch [:n, 'dry-run']
27
+
28
+ def project_path_check!(options)
29
+ exit_now!('No project given!') if options['project-path'].nil? || options['project-path'].empty?
30
+ end
31
+
32
+ def set_config(options)
33
+ Lambit::Common::Config.instance.init_config(options)
34
+ end
35
+
36
+ def bootstrap(options)
37
+ project_path_check! options
38
+ set_config options
39
+ Lambit.logger.info "Lambit CLI using options: #{options}" if Lambit.is_verbose?
40
+ end
41
+
42
+ command :build do |c|
43
+ c.action do |global_options, options, args|
44
+ bootstrap(global_options)
45
+ Lambit::Commands::Lambdas.run 'build_lambdas', global_options, args
46
+ end
47
+ end
48
+
49
+ command :deploy do |c|
50
+ c.action do |global_options, options, args|
51
+ bootstrap(global_options)
52
+ Lambit::Commands::Lambdas.run 'create_lambdas', global_options, args
53
+ end
54
+ end
55
+
56
+ command :delete do |c|
57
+ c.action do |global_options, options, args|
58
+ bootstrap(global_options)
59
+ Lambit::Commands::Lambdas.run 'delete_lambdas', global_options, args
60
+ end
61
+ end
62
+
63
+ command :add_event_sources do |c|
64
+ c.action do |global_options, options, args|
65
+ bootstrap(global_options)
66
+ Lambit::Commands::Lambdas.run 'add_event_sources_lambdas', global_options, args
67
+ end
68
+ end
69
+
70
+ command :remove_event_sources do |c|
71
+ c.action do |global_options, options, args|
72
+ bootstrap(global_options)
73
+ Lambit::Commands::Lambdas.run 'remove_event_sources_lambdas', global_options, args
74
+ end
75
+ end
76
+
77
+ command :add_alarms do |c|
78
+ c.action do |global_options, options, args|
79
+ bootstrap(global_options)
80
+ Lambit::Commands::Lambdas.run 'add_alarms_lambdas', global_options, args
81
+ end
82
+ end
83
+
84
+ command :delete_alarms do |c|
85
+ c.action do |global_options, options, args|
86
+ bootstrap(global_options)
87
+ Lambit::Commands::Lambdas.run 'delete_alarms_lambdas', global_options, args
88
+ end
89
+ end
90
+
91
+ exit run(ARGV)
@@ -0,0 +1,32 @@
1
+ # encoding: UTF-8
2
+
3
+ $:.push File.expand_path('../lib', __FILE__)
4
+ require File.expand_path('../lib/lambit/version', __FILE__)
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = 'lambit'
8
+ gem.version = Lambit::VERSION
9
+ gem.platform = Gem::Platform::RUBY
10
+ gem.authors = ['Will Drew']
11
+ gem.email = ['willdrew@gmail.com']
12
+ gem.summary = %q{}
13
+ gem.description = %q{}
14
+ gem.homepage = 'https://github.com/willdrew/lambit'
15
+
16
+ gem.required_rubygems_version = '>= 1.3.6'
17
+ gem.required_ruby_version = ::Gem::Requirement.new('>= 1.9.3')
18
+
19
+ gem.add_dependency('gli', '~> 2.13')
20
+ gem.add_dependency('aws-sdk', '~> 2.2')
21
+ gem.add_development_dependency('rake', '~> 10.4')
22
+ gem.add_development_dependency('bundler', '~> 1.7')
23
+ gem.add_development_dependency('pry', '~> 0.10')
24
+ gem.add_development_dependency('mocha', '~> 1.1')
25
+ gem.add_development_dependency('shoulda-context', '~> 1.2')
26
+
27
+ gem.files = `git ls-files`.split($\)
28
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
29
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
30
+
31
+ gem.require_paths = %w(lib)
32
+ end
@@ -0,0 +1,96 @@
1
+ name: "my-lambit-project"
2
+ type: "python"
3
+ defaults:
4
+ lambda_function: &default_lambda_function
5
+ runtime: "python2.7"
6
+ role: "arn:aws:iam::############:role/LambdaRole"
7
+ handler: "lambda_function.lambda_handler"
8
+ description: "my-lambit-project description"
9
+ memory_size: 128
10
+ timeout: 30
11
+ publish: true
12
+ code: {}
13
+ required_pips: &default_required_pips
14
+ - "arrow==0.7.0"
15
+ lambda_permission: &default_lambda_permission_s3
16
+ function_name: "#{function_name}"
17
+ statement_id: "#{function_name}-#{index}"
18
+ action: "lambda:InvokeFunction"
19
+ principal: "s3.amazonaws.com"
20
+ source_arn: "arn:aws:s3:::my-awesome-bucket"
21
+ lambda_permission: &default_lambda_permission_cron
22
+ function_name: "#{function_name}"
23
+ statement_id: "#{function_name}-#{index}"
24
+ action: "lambda:InvokeFunction"
25
+ principal: "events.amazonaws.com"
26
+ source_arn: "arn:aws:events:us-west-2:############:rule/lambit-my-lambit-function-v20160510-every-1200"
27
+ s3_bucket_notification_configurations: &default_s3_bucket_notification_configurations
28
+ bucket: "my-awesome-bucket"
29
+ notification_configuration:
30
+ lambda_function_configurations:
31
+ -
32
+ id: "#{function_name}-my-awesome-bucket-0"
33
+ lambda_function_arn: "arn:aws:lambda:us-west-2:############:function:#{function_name}"
34
+ events: ["s3:ObjectCreated:*"]
35
+ filter:
36
+ key:
37
+ filter_rules:
38
+ -
39
+ name: "prefix"
40
+ value: "really-cool-prefix"
41
+ cloudwatch_event_rule: &default_cloudwatch_event_rule_cron
42
+ name: "lambit-my-lambit-function-v20160510-every-1200"
43
+ schedule_expression: "cron(0 12 ? * * *)"
44
+ state: "ENABLED"
45
+ description: 'morning (every 1200 UTC)'
46
+ cloudwatch_event_target: &default_cloudwatch_event_target_cron
47
+ rule: "lambit-my-lambit-function-v20160510-every-1200"
48
+ targets:
49
+ -
50
+ id: "#{function_name}-#{index}"
51
+ arn: "arn:aws:lambda:us-west-2:############:function:#{function_name}"
52
+ cloudwatch_alarm: &default_cloudwatch_alarm
53
+ actions_enabled: true
54
+ alarm_actions:
55
+ - "arn:aws:sns:us-west-2:############:warnings"
56
+ namespace: "AWS/Lambda"
57
+ statistic: "Average"
58
+ period: 900
59
+ evaluation_periods: 1
60
+ threshold: 1.0
61
+ comparison_operator: "GreaterThanOrEqualToThreshold"
62
+ dimensions: []
63
+ cloudwatch_alarm_errors: &default_cloudwatch_alarm_errors
64
+ <<: *default_cloudwatch_alarm
65
+ metric_name: "Errors"
66
+ alarm_name: "#{function_name}-Errors"
67
+ dimensions:
68
+ -
69
+ name: "FunctionName"
70
+ value: "#{function_name}"
71
+ lambdas:
72
+ -
73
+ lambda_function:
74
+ <<: *default_lambda_function
75
+ function_name: "lambit-my-lambit-function-v20160510"
76
+ required_pips:
77
+ *default_required_pips
78
+ templates:
79
+ config.json:
80
+ retries: 5
81
+ lambda_permissions:
82
+ -
83
+ <<: *default_lambda_permission_s3
84
+ <<: *default_lambda_permission_cron
85
+ s3_bucket_notification_configurations:
86
+ -
87
+ <<: *default_s3_bucket_notification_configurations
88
+ cloudwatch_event_rules:
89
+ -
90
+ <<: *default_cloudwatch_event_rule_cron
91
+ cloudwatch_event_targets:
92
+ -
93
+ <<: *default_cloudwatch_event_target_cron
94
+ cloudwatch_alarms:
95
+ -
96
+ <<: *default_cloudwatch_alarm_errors
@@ -0,0 +1,6 @@
1
+ # encoding: UTF-8
2
+
3
+ require_relative 'lambit/common'
4
+ require_relative 'lambit/aws'
5
+ require_relative 'lambit/commands'
6
+ require_relative 'lambit/version'
@@ -0,0 +1,9 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'aws-sdk'
4
+
5
+ require_relative 'aws/cloud_watch/alarm'
6
+ require_relative 'aws/cloud_watch_events/rule'
7
+ require_relative 'aws/lambda/function'
8
+ require_relative 'aws/lambda/permission'
9
+ require_relative 'aws/s3/bucket_notification_configuration'
@@ -0,0 +1,59 @@
1
+ # encoding: UTF-8
2
+
3
+ module Lambit
4
+ module Aws
5
+ module CloudWatch
6
+ class Alarm
7
+ OPTIONS = [
8
+ :alarm_name,
9
+ :alarm_description,
10
+ :actions_enabled,
11
+ :ok_actions,
12
+ :alarm_actions,
13
+ :insufficient_data_actions,
14
+ :metric_name,
15
+ :namespace,
16
+ :statistic,
17
+ :dimensions,
18
+ :period,
19
+ :unit,
20
+ :evaluation_periods,
21
+ :threshold,
22
+ :comparison_operator,
23
+ :alarm_names
24
+ ].each { |option| attr_reader option }
25
+
26
+ attr_reader :client
27
+ attr_reader :options
28
+
29
+ def initialize(config)
30
+ @client = ::Aws::CloudWatch::Client.new
31
+
32
+ OPTIONS.each do |option|
33
+ if config.has_key?(option)
34
+ instance_variable_set("@#{option}", config[option])
35
+ end
36
+ end
37
+ end
38
+
39
+ def options
40
+ options = {}
41
+
42
+ OPTIONS.each do |option|
43
+ value = self.send(option)
44
+ options[option] = value unless value.nil?
45
+ end
46
+ options
47
+ end
48
+
49
+ def put_metric_alarm
50
+ self.client.put_metric_alarm options
51
+ end
52
+
53
+ def delete_alarms
54
+ self.client.delete_alarms options
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end