tck-lambdas 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE +21 -0
- data/README.md +107 -0
- data/exe/tck-lambdas +3 -0
- data/lib/tck/lambdas.rb +2 -0
- data/lib/tck/lambdas/Gemfile +10 -0
- data/lib/tck/lambdas/Rakefile +12 -0
- data/lib/tck/lambdas/aws_function.rb +74 -0
- data/lib/tck/lambdas/cli.rb +44 -0
- data/lib/tck/lambdas/contact_form/source/conf.js +13 -0
- data/lib/tck/lambdas/contact_form/source/contact_form.js +58 -0
- data/lib/tck/lambdas/contact_form/source/utils.js +21 -0
- data/lib/tck/lambdas/contact_form/test/failed/domain_empty.json +7 -0
- data/lib/tck/lambdas/contact_form/test/failed/domain_not_found.json +8 -0
- data/lib/tck/lambdas/contact_form/test/failed/email_empty.json +7 -0
- data/lib/tck/lambdas/contact_form/test/failed/email_format.json +8 -0
- data/lib/tck/lambdas/contact_form/test/failed/message_empty.json +7 -0
- data/lib/tck/lambdas/contact_form/test/succeeded/basic.json +8 -0
- data/lib/tck/lambdas/contact_form/test/succeeded/with_cc.json +9 -0
- data/lib/tck/lambdas/templates/lambdas.rake.erb +54 -0
- data/lib/tck/lambdas/templates/lambdas.yml.erb +9 -0
- data/lib/tck/lambdas/test.rb +31 -0
- data/lib/tck/lambdas/version.rb +5 -0
- metadata +123 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 991043c924a86317c83c10887ef66bd2b6ea375a
|
4
|
+
data.tar.gz: fec64010314f12a60d4008c24bf9d008c75db400
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c9eb6303bd232a315ace43c9114c5f1c0239b38ee83d65506aef637692e38e8f0121775c9b161c5e614fa47e4211b0e8dcc161b02fa31e9819b6bfd71f391815
|
7
|
+
data.tar.gz: 8fb8108486f0d6f9b344b4f4c544c42f7985c6601f4bb6dfb5a74e186f11d2fbcd129ebcd61bba1c088f2c73fb23544ff4c21dcc7cbaca29a45f51750d234997
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 The Cocktail Experience, S.L.
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, 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,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
# Tck::Lambdas
|
2
|
+
|
3
|
+
_Tck::Lambdas_ es una _gema_ que facilita la utilización de una _AWS Lambda_ en el contexto de un proyecto _Ruby_ introduciendo en el mismo tareas de _Rake_ que realizan las **órdenes AWS** que debemos ejecutar habitualmente desde la _línea de comandos_.
|
4
|
+
|
5
|
+
Por ejemplo, si tenemos una _función lambda_ llamada **shine** y queremos subir una mejora en su código tendríamos que, por un lado generar el _zip_ con dicha mejora, y por otro actualizar el mismo en _AWS Lambda_ (con la función ``aws lambda update-function-code`` o a través de su consola web).
|
6
|
+
|
7
|
+
Si hemos instalado la gema _Tck::Lambdas_ en nuestro proyecto y hemos indicado en que el mismo hace uso de la _lambda shine_ (bundle exec ``tck-lambdas use shine``), lanzaríamos la siguiente orden para crear el _zip_:
|
8
|
+
|
9
|
+
$ rake lambdas:shine:create_zip
|
10
|
+
|
11
|
+
Y esta para subir el mismo a _AWS Lambda_ (para _"desplegar"_ la mejora):
|
12
|
+
|
13
|
+
$ rake lambdas:shine:upload_zip
|
14
|
+
|
15
|
+
Si sólo tenemos esa _lambda_, creando el _alias_ necesario en nuestro _Rakefile_ (``task deploy_lambda: "lambdas:shine:upload_zip"``) podríamos lanzar simplemente:
|
16
|
+
|
17
|
+
$ rake deploy_lambda
|
18
|
+
|
19
|
+
Usando una _lambda_
|
20
|
+
-------------------
|
21
|
+
|
22
|
+
Vamos a meter un _formulario de contacto_ en nuestro **proyecto Amazing** y queremos usar la *lambda contact_form*. Instalamos la _gema Tck::Lambdas_ y le indicamos que nuestro proyecto hace uso de la _lambda_ llamada *contact_form*:
|
23
|
+
|
24
|
+
$ echo "gem 'tck-lambdas'" >> Gemfile # Metemos la gema en nuestro Gemfile...
|
25
|
+
$ bundle # - la instalamos y...
|
26
|
+
$ bundle exec tck-lambdas use contact_form # - y usamos la lambda:
|
27
|
+
=> lambdas/contact_form/ created with the lambda sources & tests.
|
28
|
+
=> task/lambdas/contact_form.rake created with common tasks.
|
29
|
+
=> .lambdas.yml created with the contact_form lambda conf.
|
30
|
+
|
31
|
+
Tal y como nos avisa ha creado, entre otras cosas, el fichero *.lambdas.yml* con la configuración para nuestra función _lambda_ con el siguiente contenido:
|
32
|
+
|
33
|
+
contact_form:
|
34
|
+
function-name: tck_project_contact_form
|
35
|
+
handler: tck_project_contact_form.handler
|
36
|
+
timeout: 30
|
37
|
+
memory-size: 128
|
38
|
+
runtime: nodejs4.3
|
39
|
+
role: lambda_contact_form_role
|
40
|
+
|
41
|
+
Todos los valores por defecto deberían ser válidos excepto el nombre de la función (_function-name_), su manejador (_handler_), y su role.
|
42
|
+
|
43
|
+
En el nombre del la función y su manejador tenemos que sustituir *tck_project* por el nombre de nuestro proyecto (quedándonos con *amazing_contact_form* y *amazing_contact_form.handler* respectivamente).
|
44
|
+
|
45
|
+
El role tenemos que sustituirlo por el que corresponda de los que nos devuelve AWS:
|
46
|
+
|
47
|
+
aws iam list-roles --query "Roles[].[RoleName,Arn]"
|
48
|
+
|
49
|
+
Con dichos cambios en nuestro *.lambdas.yml* ejecutamos la siguiente tarea de _rake_:
|
50
|
+
|
51
|
+
$ rake lambdas:contact_form:create_lambda
|
52
|
+
|
53
|
+
Dicha orden nos creará, **además de la función _lambda_** necesaria para el entorno de producción, **otra con el mismo nombre terminada en *_test* para la ejecución de sus tests** (en nuestro ejemplo si lanzamos ``aws lambda list-functions`` deberíamos tener dos nuevas funciones llamadas *amazing_contact_form* y *amazing_contact_form_test*).
|
54
|
+
|
55
|
+
Por lo tanto, si todo ha ido bien deberíamos poder lanzar los tests de nuestra _lambda_ con éxito:
|
56
|
+
|
57
|
+
$ rake lambdas:contact_form:test
|
58
|
+
|
59
|
+
Modificando una _lambda_
|
60
|
+
------------------------
|
61
|
+
|
62
|
+
El código de la _lambda_ lo tenemos dentro de *lambdas/contact_form/source* y para añadir una mejora al mismo debemos seguir los siguientes pasos de cara a desplegarla:
|
63
|
+
|
64
|
+
1. Escribir la mejora
|
65
|
+
2. Crear el _zip_:
|
66
|
+
``rake lambdas:contact_form:create_zip``
|
67
|
+
3. Subir el nuevo _zip_ a la _lambda_ de tests:
|
68
|
+
``rake lambdas:contact_form:upload_test``
|
69
|
+
4. Lanzar los tests:
|
70
|
+
``rake lambdas:contact_form:test``
|
71
|
+
(...volviendo al primer paso hasta que pasen)
|
72
|
+
5. Actualizar la _lambda_ de producción:
|
73
|
+
``rake lambdas:contact_form:upload_zip``
|
74
|
+
|
75
|
+
Los pasos 2, 3 y 4 son implementados por la tarea **:build_lambda**, lo que nos permite reducir los pasos necesarios a 3:
|
76
|
+
|
77
|
+
1. Escribir la mejora
|
78
|
+
2. Lanzar el _build_:
|
79
|
+
``rake lambdas:contact_form:build_lambda``
|
80
|
+
(...hasta que pasen los tests)
|
81
|
+
3. Actualizar la _lambda_ de producción:
|
82
|
+
``rake lambdas:contact_form:upload_zip``
|
83
|
+
|
84
|
+
## Installation
|
85
|
+
|
86
|
+
Add this line to your application's Gemfile:
|
87
|
+
|
88
|
+
```ruby
|
89
|
+
gem 'tck-lambdas'
|
90
|
+
```
|
91
|
+
|
92
|
+
And then execute:
|
93
|
+
|
94
|
+
$ bundle
|
95
|
+
|
96
|
+
Or install it yourself as:
|
97
|
+
|
98
|
+
$ gem install tck-lambdas
|
99
|
+
|
100
|
+
## Contributing
|
101
|
+
|
102
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/tck-lambdas. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
103
|
+
|
104
|
+
|
105
|
+
## License
|
106
|
+
|
107
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/exe/tck-lambdas
ADDED
data/lib/tck/lambdas.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# Copyright 2016 The Cocktail Experience, S.L.
|
2
|
+
require "rake/testtask"
|
3
|
+
|
4
|
+
require_relative "lib/tck/lambdas/aws_function"
|
5
|
+
load "lib/tasks/lambdas.rake"
|
6
|
+
|
7
|
+
namespace :lambdas do
|
8
|
+
Rake::TestTask.new(:test) do |t|
|
9
|
+
t.libs = %w(lib)
|
10
|
+
t.pattern = "lambdas/test.rb"
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
# Copyright (c) The Cocktail Experience S.L. (2016)
|
2
|
+
require "yaml"
|
3
|
+
require "tmpdir"
|
4
|
+
|
5
|
+
module Tck
|
6
|
+
module Lambdas
|
7
|
+
class AwsFunction
|
8
|
+
attr_reader :name
|
9
|
+
attr_reader :conf
|
10
|
+
|
11
|
+
def self.tmpdir
|
12
|
+
@tmpdir ||= Dir.tmpdir + "/tck_lambdas"
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.yaml
|
16
|
+
@yaml ||= File.exist?('.lambdas.yml') ? YAML.load_file('.lambdas.yml') : nil
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.clean_tmps!
|
20
|
+
FileUtils.mkdir_p tmpdir
|
21
|
+
FileUtils.rm_rf Dir.glob("#{tmpdir}/*")
|
22
|
+
end
|
23
|
+
|
24
|
+
def initialize(name)
|
25
|
+
@name = name.to_s
|
26
|
+
@conf = yaml[@name]
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_function_name
|
30
|
+
"#{@conf['function-name']}_test"
|
31
|
+
end
|
32
|
+
|
33
|
+
def method_missing(method, *args, &block)
|
34
|
+
m = method.to_s
|
35
|
+
@conf[m] || @conf[m.gsub("_","-")] || super
|
36
|
+
end
|
37
|
+
|
38
|
+
def dir
|
39
|
+
@dir ||= "lambdas/#{name}"
|
40
|
+
end
|
41
|
+
|
42
|
+
def tmpdir
|
43
|
+
self.class.tmpdir
|
44
|
+
end
|
45
|
+
|
46
|
+
def zip_file
|
47
|
+
@zip_file ||= "#{tmpdir}/#{function_name}.zip"
|
48
|
+
end
|
49
|
+
|
50
|
+
def invoke_events_in_directory(event_type)
|
51
|
+
puts "lambdas/#{name}/#{event_type}/*.json"
|
52
|
+
Dir["lambdas/#{name}/test/#{event_type}/*.json"].each do |json_file|
|
53
|
+
filename = File.basename(json_file)
|
54
|
+
output = "#{tmpdir}/#{filename}.output"
|
55
|
+
invoke_lambda json_file, output
|
56
|
+
yield filename, File.read(output)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def invoke_lambda(payload_file, output_file)
|
61
|
+
cmd = "aws lambda invoke " <<
|
62
|
+
"--function-name #{@conf['function-name']}_test " <<
|
63
|
+
"--payload file://#{payload_file} #{output_file}"
|
64
|
+
puts "$ #{cmd}"
|
65
|
+
`#{cmd}`
|
66
|
+
end
|
67
|
+
|
68
|
+
def yaml
|
69
|
+
self.class.yaml
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# Copyright (c) The Cocktail Experience S.L. (2016)
|
2
|
+
require "thor"
|
3
|
+
require_relative "aws_function"
|
4
|
+
|
5
|
+
module Tck
|
6
|
+
module Lambdas
|
7
|
+
class CLI < Thor
|
8
|
+
include Thor::Actions
|
9
|
+
|
10
|
+
def self.source_root
|
11
|
+
File.dirname(__FILE__)
|
12
|
+
end
|
13
|
+
|
14
|
+
desc "list", "List currently used functions in AWS Lambda."
|
15
|
+
def list
|
16
|
+
if yaml = Tck::Lambdas::AwsFunction.yaml
|
17
|
+
yaml.each do |lambda_name, properties|
|
18
|
+
puts " - #{properties["function-name"]} (cloned from '#{lambda_name}')"
|
19
|
+
end
|
20
|
+
else
|
21
|
+
puts "No lambdas found in this directory... :("
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
desc "use NAME", "Use the AWS Lambda function known as NAME at The Cocktail."
|
26
|
+
def use(name)
|
27
|
+
puts "#{CLI.source_root}/#{name}"
|
28
|
+
if File.directory?("#{CLI.source_root}/#{name}")
|
29
|
+
@lambda = Tck::Lambdas::AwsFunction.new(name)
|
30
|
+
|
31
|
+
copy_file "Rakefile"
|
32
|
+
copy_file "Gemfile"
|
33
|
+
template "templates/lambdas.yml.erb", ".lambdas.yml"
|
34
|
+
template "templates/lambdas.rake.erb", "lib/tasks/lambdas.rake"
|
35
|
+
copy_file "aws_function.rb", "lib/tck/lambdas/aws_function.rb"
|
36
|
+
copy_file "test.rb", "lambdas/test.rb"
|
37
|
+
directory name, "lambdas/#{name}"
|
38
|
+
else
|
39
|
+
raise "Sorry, '#{name}' is not a valid lambda name."
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
/* Copyright 2016 The Cocktail Experience, S.L. */
|
2
|
+
module.exports = {
|
3
|
+
domains: {
|
4
|
+
'the-cocktail.com': {
|
5
|
+
emailAddress: "Contact Form Lambda <tests@the-cocktail.com>",
|
6
|
+
emailSubject: "New contact submitted in the contact form"
|
7
|
+
},
|
8
|
+
'thecocktailventures.com': {
|
9
|
+
emailAddress: "TckVentures Website <ventures@the-cocktail.com>",
|
10
|
+
emailSubject: "New contact with The Cocktail Ventures"
|
11
|
+
}
|
12
|
+
}
|
13
|
+
}
|
@@ -0,0 +1,58 @@
|
|
1
|
+
/* Copyright 2016 The Cocktail Experience, S.L. */
|
2
|
+
var AWS = require('aws-sdk');
|
3
|
+
var ses = new AWS.SES({apiVersion: '2010-12-01'});
|
4
|
+
var conf = require('./conf');
|
5
|
+
var utils = require('./utils');
|
6
|
+
|
7
|
+
exports.handler = function(event, context) {
|
8
|
+
console.log('Received event:', JSON.stringify(event, null, 2));
|
9
|
+
|
10
|
+
if (!event.domain) { context.fail('domain: empty'); return; }
|
11
|
+
|
12
|
+
var domain = conf.domains[event.domain];
|
13
|
+
|
14
|
+
if (!domain) { context.fail('domain: not found'); return; }
|
15
|
+
|
16
|
+
console.log(domain.emailAddress);
|
17
|
+
|
18
|
+
if (!event.email) { context.fail('email: empty'); return; }
|
19
|
+
if (!event.message || event.message === '') { context.fail('message: empty'); return; }
|
20
|
+
|
21
|
+
var email = unescape(event.email);
|
22
|
+
if (!utils.validateEmail(email)) { context.fail('email: format'); return; }
|
23
|
+
|
24
|
+
var messageParts = [];
|
25
|
+
|
26
|
+
if (event.name) messageParts.push("Name: " + event.name);
|
27
|
+
if (event.company) messageParts.push("Company: " + event.company);
|
28
|
+
if (event.phone) messageParts.push("Phone: " + event.phone);
|
29
|
+
messageParts.push("Email: " + event.email);
|
30
|
+
messageParts.push("\r\n" + event.message);
|
31
|
+
|
32
|
+
var params = {
|
33
|
+
Destination: {
|
34
|
+
ToAddresses: [ domain.emailAddress ],
|
35
|
+
BccAddresses: [ "fernando.gs@gmail.com" ]
|
36
|
+
},
|
37
|
+
Message: {
|
38
|
+
Body: { Text: { Data: messageParts.join("\r\n"), Charset: 'UTF-8' } },
|
39
|
+
Subject: { Data: domain.emailSubject, Charset: 'UTF-8' }
|
40
|
+
},
|
41
|
+
Source: domain.emailAddress,
|
42
|
+
ReplyToAddresses: [ email ]
|
43
|
+
};
|
44
|
+
|
45
|
+
if ((event.cc) && (event.cc == "1")) {
|
46
|
+
params.Destination.CcAddresses = [ event.email ];
|
47
|
+
}
|
48
|
+
|
49
|
+
ses.sendEmail(params, function(err, data) {
|
50
|
+
if (err) {
|
51
|
+
console.log(err, err.stack);
|
52
|
+
context.fail(err);
|
53
|
+
} else {
|
54
|
+
console.log(data);
|
55
|
+
context.succeed(0);
|
56
|
+
}
|
57
|
+
});
|
58
|
+
};
|
@@ -0,0 +1,21 @@
|
|
1
|
+
/* Copyright 2016 The Cocktail Experience, S.L. */
|
2
|
+
module.exports = {
|
3
|
+
validateEmail: function(email) {
|
4
|
+
var tester = /^[-!#$%&'*+\/0-9=?A-Z^_a-z{|}~](\.?[-!#$%&'*+/0-9=?A-Z^_a-z`{|}~])*@[a-zA-Z0-9](-?\.?[a-zA-Z0-9])*(\.[a-zA-Z](-?[a-zA-Z0-9])*)+$/;
|
5
|
+
if (!email) return false;
|
6
|
+
|
7
|
+
if(email.length>254) return false;
|
8
|
+
|
9
|
+
var valid = tester.test(email);
|
10
|
+
if(!valid) return false;
|
11
|
+
|
12
|
+
// Further checking of some things regex can't handle
|
13
|
+
var parts = email.split("@");
|
14
|
+
if(parts[0].length>64) return false;
|
15
|
+
|
16
|
+
var domainParts = parts[1].split(".");
|
17
|
+
if(domainParts.some(function(part) { return part.length>63; })) return false;
|
18
|
+
|
19
|
+
return true;
|
20
|
+
}
|
21
|
+
}
|
@@ -0,0 +1,54 @@
|
|
1
|
+
namespace :lambdas do
|
2
|
+
namespace :<%= @lambda.name %> do
|
3
|
+
task test: "lambdas:test"
|
4
|
+
|
5
|
+
desc "Update the <%= @lambda.name %> lambda code (creating & uploading the ZIP file)"
|
6
|
+
task upload_zip: :create_zip do
|
7
|
+
tck_lambda = Tck::Lambdas::AwsFunction.new(:<%= @lambda.name %>)
|
8
|
+
|
9
|
+
params = "--function-name #{tck_lambda.function_name} " <<
|
10
|
+
"--zip-file fileb://#{tck_lambda.zip_file}"
|
11
|
+
|
12
|
+
puts `aws lambda update-function-code #{params}`
|
13
|
+
end
|
14
|
+
|
15
|
+
desc "Generate lambda's ZIP file w/ source/* code"
|
16
|
+
task :create_zip do
|
17
|
+
tck_lambda = Tck::Lambdas::AwsFunction.new(:<%= @lambda.name %>)
|
18
|
+
puts "Creating #{tck_lambda.zip_file}..."
|
19
|
+
FileUtils.rm(tck_lambda.zip_file, force: true)
|
20
|
+
cmd = "cd #{tck_lambda.dir}/source &&\\\n" <<
|
21
|
+
"mv #{tck_lambda.name}.js #{tck_lambda.function_name}.js &&\\\n" <<
|
22
|
+
"zip -r #{tck_lambda.zip_file} * &&\\\n" <<
|
23
|
+
"mv #{tck_lambda.function_name}.js #{tck_lambda.name}.js"
|
24
|
+
puts cmd
|
25
|
+
puts `#{cmd}`
|
26
|
+
end
|
27
|
+
|
28
|
+
desc "Create the <%= @lambda.name %> lambda function in AWS Lambda w/ .lambda.yml."
|
29
|
+
task create_lambda: :create_zip do
|
30
|
+
tck_lambda = Tck::Lambdas::AwsFunction.new(:<%= @lambda.name %>)
|
31
|
+
puts "\n#{tck_lambda.function_name} & #{tck_lambda.test_function_name} lambdas will be created with:"
|
32
|
+
puts "\n #{tck_lambda.zip_file}\n\n...using the following parameters read from current .lambdas.yml:"
|
33
|
+
tck_lambda.conf.each do |prop, value|
|
34
|
+
puts " - #{prop}: #{value}"
|
35
|
+
end
|
36
|
+
[]
|
37
|
+
printf "\nContinue?? Press [Ctrl+C] to cancel."
|
38
|
+
STDIN.gets
|
39
|
+
[tck_lambda.function_name, tck_lambda.test_function_name].each do |function_name|
|
40
|
+
params = "--function-name #{function_name} " <<
|
41
|
+
"--handler #{tck_lambda.handler} " <<
|
42
|
+
"--runtime #{tck_lambda.runtime} " <<
|
43
|
+
"--role #{tck_lambda.role} " <<
|
44
|
+
"--memory-size #{tck_lambda.memory_size} " <<
|
45
|
+
"--timeout #{tck_lambda.timeout} " <<
|
46
|
+
"--description \"#{tck_lambda.description}\" " <<
|
47
|
+
"--zip-file fileb://#{tck_lambda.zip_file}"
|
48
|
+
cmd = "aws lambda create-function #{params}"
|
49
|
+
puts cmd
|
50
|
+
puts `#{cmd}`
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
# The Cockatil's AWS Lambda functions configuration
|
2
|
+
<%= @lambda.name %>:
|
3
|
+
function-name: project_name_<%= @lambda.name %>
|
4
|
+
handler: project_name_<%= @lambda.name %>.handler
|
5
|
+
timeout: 30
|
6
|
+
memory-size: 128
|
7
|
+
runtime: nodejs4.3
|
8
|
+
role: lambda_<%= @lambda.name %>_role
|
9
|
+
description: Project-Name instance of the Tck's <%= @lambda.name %> lambda
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# Copyright 2016 The Cocktail Experience, S.L.
|
2
|
+
require "minitest/autorun"
|
3
|
+
require "json"
|
4
|
+
require_relative "../lib/tck/lambdas/aws_function"
|
5
|
+
|
6
|
+
Tck::Lambdas::AwsFunction.clean_tmps!
|
7
|
+
|
8
|
+
Dir['lambdas/*/'].each do |directory|
|
9
|
+
lambda_name = directory[8..-2]
|
10
|
+
|
11
|
+
describe "The Cocktail #{lambda_name} lambda" do
|
12
|
+
it "returns 0 when the payload has the right params" do
|
13
|
+
aws_lambda = Tck::Lambdas::AwsFunction.new(lambda_name)
|
14
|
+
puts "\nTesting #{aws_lambda.function_name} lambda SUCCESS scenarios:"
|
15
|
+
aws_lambda.invoke_events_in_directory("succeeded") do |filename, output|
|
16
|
+
expect(output).must_equal "0"
|
17
|
+
puts "OK!"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
it "returns the right error for each wrong payload" do
|
22
|
+
aws_lambda = Tck::Lambdas::AwsFunction.new(lambda_name)
|
23
|
+
puts "\nTesting #{aws_lambda.function_name} lambda FAILURE scenarios:"
|
24
|
+
aws_lambda.invoke_events_in_directory("failed") do |filename, output|
|
25
|
+
error_words = JSON.parse(output)["errorMessage"].scan(/(\w+)/)
|
26
|
+
expect(error_words.join("_").+(".json")).must_equal filename
|
27
|
+
puts "OK!"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
metadata
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tck-lambdas
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Fernando Garcia Samblas
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-07-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: thor
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.12'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.12'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: minitest
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '5.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '5.0'
|
69
|
+
description: A Ruby's Rake wrapper over the *aws lambda* CLI (aws-cli/1.10.37).
|
70
|
+
email:
|
71
|
+
- fernando.garcia@the-cocktail.com
|
72
|
+
executables:
|
73
|
+
- tck-lambdas
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- LICENSE
|
78
|
+
- README.md
|
79
|
+
- exe/tck-lambdas
|
80
|
+
- lib/tck/lambdas.rb
|
81
|
+
- lib/tck/lambdas/Gemfile
|
82
|
+
- lib/tck/lambdas/Rakefile
|
83
|
+
- lib/tck/lambdas/aws_function.rb
|
84
|
+
- lib/tck/lambdas/cli.rb
|
85
|
+
- lib/tck/lambdas/contact_form/source/conf.js
|
86
|
+
- lib/tck/lambdas/contact_form/source/contact_form.js
|
87
|
+
- lib/tck/lambdas/contact_form/source/utils.js
|
88
|
+
- lib/tck/lambdas/contact_form/test/failed/domain_empty.json
|
89
|
+
- lib/tck/lambdas/contact_form/test/failed/domain_not_found.json
|
90
|
+
- lib/tck/lambdas/contact_form/test/failed/email_empty.json
|
91
|
+
- lib/tck/lambdas/contact_form/test/failed/email_format.json
|
92
|
+
- lib/tck/lambdas/contact_form/test/failed/message_empty.json
|
93
|
+
- lib/tck/lambdas/contact_form/test/succeeded/basic.json
|
94
|
+
- lib/tck/lambdas/contact_form/test/succeeded/with_cc.json
|
95
|
+
- lib/tck/lambdas/templates/lambdas.rake.erb
|
96
|
+
- lib/tck/lambdas/templates/lambdas.yml.erb
|
97
|
+
- lib/tck/lambdas/test.rb
|
98
|
+
- lib/tck/lambdas/version.rb
|
99
|
+
homepage: https://github.com/the-cocktail/tck-lambdas
|
100
|
+
licenses:
|
101
|
+
- MIT
|
102
|
+
metadata: {}
|
103
|
+
post_install_message:
|
104
|
+
rdoc_options: []
|
105
|
+
require_paths:
|
106
|
+
- lib
|
107
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - ">="
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
112
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
requirements: []
|
118
|
+
rubyforge_project:
|
119
|
+
rubygems_version: 2.5.1
|
120
|
+
signing_key:
|
121
|
+
specification_version: 4
|
122
|
+
summary: The Cocktail's AWS Lambda functions manager.
|
123
|
+
test_files: []
|