faux-lambda 0.5
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/.gitignore +2 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +19 -0
- data/README.md +78 -0
- data/bin/faux-lambda +82 -0
- data/faux-lambda.gemspec +19 -0
- data/lib/faux_lambda/version.rb +3 -0
- metadata +67 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 27f64243cbe049392b836b5e6dbb7c9af0308bed
|
4
|
+
data.tar.gz: aff20d710af04c063beb96a287d80c3f5f2bc6f0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3a7cbf03b35a0d9e7a4cfe76705d254bbdfbbed48a52801eb5c95903650a7c0bcf0bcb27eb2ebe1ef179a6e609852dc476510253aba0c300710b56fa6f32b82c
|
7
|
+
data.tar.gz: 58ecad0b190c54a694a431e6659ac94dbf75603811fda1c1f8fd37a5d328e3517e99acdc6a9f8669c200a72dcb51ffedd611ebf5ec6456a0a538e8cd75efed05
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
data/README.md
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
# Faux Lambda server for testing
|
2
|
+
|
3
|
+
Lambda service mock implementation for testing and exploration. It starts a simple web server (default is http://localhost:9123) and processes Lambda invocation requests. It can be used both programmatically and as a command line tool.
|
4
|
+
|
5
|
+
## As a command line tool
|
6
|
+
|
7
|
+
In its simplest form:
|
8
|
+
```
|
9
|
+
gem install faux-lambda
|
10
|
+
faux-lambda --reply='{}' &
|
11
|
+
aws --endpoint http://localhost:9123 lambda invoke --function-name whatever
|
12
|
+
```
|
13
|
+
|
14
|
+
The CLI can also simulate specific scenarios:
|
15
|
+
```
|
16
|
+
$ faux-lambda --function=foo --reply='{}' --function=bar --reply='{}' --reply='{}' --fail &
|
17
|
+
$ aws --endpoint http://localhost:12345 lambda invoke --function-name foo
|
18
|
+
Called foo with ...
|
19
|
+
{}
|
20
|
+
```
|
21
|
+
Here, each call to function `foo` gets reply `{}`, first call to function `bar` gets `{}`, second gets `{}` and third will fail.
|
22
|
+
|
23
|
+
You can also pipe in replies from `stdin`, one reply per object (may contain newlines):
|
24
|
+
```
|
25
|
+
faux-lambda --function=foo <<<EOF
|
26
|
+
{}
|
27
|
+
{}
|
28
|
+
EOF
|
29
|
+
```
|
30
|
+
In this mode, the CLI will accept only one function, but may prove useful where there are numerous or large replies.
|
31
|
+
|
32
|
+
```
|
33
|
+
Usage: faux-lambda [options]
|
34
|
+
Query specifiers:
|
35
|
+
--function-name=regex
|
36
|
+
--async Require invocation to be async
|
37
|
+
--sync Require invocation to be sync
|
38
|
+
Reply specifiers:
|
39
|
+
--reply=json Send this reply
|
40
|
+
--fail ...
|
41
|
+
Various:
|
42
|
+
--quiet Don't log sent and received messages
|
43
|
+
--version
|
44
|
+
```
|
45
|
+
|
46
|
+
## faux-lambda as a library
|
47
|
+
|
48
|
+
You can use `faux-lambda` programmatically too, like so:
|
49
|
+
```
|
50
|
+
require `faux-lambda`
|
51
|
+
lambda = FauxLambda.new(port: 12345).handle do |call|
|
52
|
+
return if call.async
|
53
|
+
if call.function_name == 'foo'
|
54
|
+
'{}'
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
Aws::Lambda.new(endpoint: lambda.endpoint).invoke(...)
|
59
|
+
```
|
60
|
+
|
61
|
+
## faux-lambda in your specs
|
62
|
+
|
63
|
+
Or in your specs as if FauxLambda were an `rspec-mocks` double:
|
64
|
+
```
|
65
|
+
let(:lambda) { FauxLambda.new }
|
66
|
+
before do
|
67
|
+
allow(lambda).to receive(:incrementer).and_return(43)
|
68
|
+
end
|
69
|
+
|
70
|
+
subject do
|
71
|
+
ThingUnderTest.new(lambda.endpoint).do_math(42)
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'invokes lambda and returns its value' do
|
75
|
+
expect(subject).to equal(43)
|
76
|
+
expect(lambda).to have_received(:incrementer).with(value: 42)
|
77
|
+
end
|
78
|
+
```
|
data/bin/faux-lambda
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rack'
|
4
|
+
require 'webrick'
|
5
|
+
require 'optparse'
|
6
|
+
require_relative '../lib/faux_lambda/version'
|
7
|
+
|
8
|
+
options = {
|
9
|
+
port: 9123,
|
10
|
+
bind: '127.0.0.1',
|
11
|
+
}
|
12
|
+
|
13
|
+
functions = {
|
14
|
+
default: {
|
15
|
+
invocation_type: nil,
|
16
|
+
replies: []
|
17
|
+
}
|
18
|
+
}
|
19
|
+
|
20
|
+
current_function = :default
|
21
|
+
parser = OptionParser.new do |opts|
|
22
|
+
opts.banner = "AWS Lambda debugging endpoint, version #{FauxLambda::VERSION}."
|
23
|
+
opts.separator('')
|
24
|
+
opts.separator('Usage: faux-lambda --reply "Hello world!"')
|
25
|
+
opts.on('--function name', '-f name', 'Name of function to expect, optionally with :<qualifier>') do |function_name|
|
26
|
+
current_function = function_name
|
27
|
+
functions[current_function] = {replies: []}
|
28
|
+
end
|
29
|
+
opts.on('--reply payload', '-r payload', 'Data to respond with') do |payload|
|
30
|
+
functions[current_function][:replies] << payload
|
31
|
+
end
|
32
|
+
opts.on('--fail', 'AWS Lambda framework gives 400') do
|
33
|
+
functions[current_function][:replies] << :fail
|
34
|
+
end
|
35
|
+
end
|
36
|
+
parser.parse!
|
37
|
+
|
38
|
+
def reply_from(replies)
|
39
|
+
if replies.size > 1
|
40
|
+
replies.shift
|
41
|
+
elsif replies.size == 1
|
42
|
+
replies.last
|
43
|
+
else
|
44
|
+
nil
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def function_data(functions, function_name, qualifier)
|
49
|
+
qualified_function_name = if qualifier
|
50
|
+
"#{function_name}:#{qualifier}"
|
51
|
+
end
|
52
|
+
functions[qualified_function_name] || functions[function_name] || functions[:default]
|
53
|
+
end
|
54
|
+
|
55
|
+
app = Proc.new do |env|
|
56
|
+
_, version, _, function_name, _ = env['REQUEST_PATH'].split('/')
|
57
|
+
raise "Unknown version #{version}" unless version == '2015-03-31'
|
58
|
+
qs = Rack::Utils.parse_nested_query(env["QUERY_STRING"])
|
59
|
+
|
60
|
+
data = function_data(functions, function_name, qs["Qualifier"])
|
61
|
+
reply = reply_from(data[:replies])
|
62
|
+
if reply.nil?
|
63
|
+
status_code = '404'
|
64
|
+
reply = 'Not found'
|
65
|
+
elsif reply == :fail
|
66
|
+
status_code = '400'
|
67
|
+
reply = 'Failed'
|
68
|
+
else
|
69
|
+
status_code = '200'
|
70
|
+
end
|
71
|
+
|
72
|
+
headers = {'Content-Type' => 'application/octet-stream'}
|
73
|
+
[status_code, headers, [reply]]
|
74
|
+
end
|
75
|
+
|
76
|
+
Rack::Handler::WEBrick.run(
|
77
|
+
app,
|
78
|
+
Port: options[:port],
|
79
|
+
BindAddress: options[:bind],
|
80
|
+
Logger: WEBrick::Log.new($stderr, WEBrick::Log::ERROR),
|
81
|
+
AccessLog: [['/dev/null', WEBrick::AccessLog::COMMON_LOG_FORMAT]]
|
82
|
+
)
|
data/faux-lambda.gemspec
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require File.expand_path('../lib/faux_lambda/version', __FILE__)
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = 'faux-lambda'
|
5
|
+
spec.version = FauxLambda::VERSION
|
6
|
+
spec.summary = 'faux-lambda provides a simple tool to mock AWS Lambda endpoint'
|
7
|
+
spec.description = 'faux-lambda is a toolbox to make it easier to develop client that call AWS Lambda functions. A simple CLI lets you mock AWS Lambda and specify replies for specific function as well as simulate AWS Lambda framework failures.'
|
8
|
+
spec.authors = ['Anders Qvist']
|
9
|
+
spec.email = 'quest@lysator.liu.se'
|
10
|
+
spec.homepage = 'https://github.com/bittrance/faux-lambda'
|
11
|
+
spec.license = 'MIT'
|
12
|
+
|
13
|
+
spec.executables = ['faux-lambda']
|
14
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(/^spec/) }
|
15
|
+
|
16
|
+
spec.required_ruby_version = '>= 2.0.0'
|
17
|
+
|
18
|
+
spec.add_runtime_dependency 'rack', '~> 2.0'
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: faux-lambda
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.5'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Anders Qvist
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-11-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rack
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
27
|
+
description: faux-lambda is a toolbox to make it easier to develop client that call
|
28
|
+
AWS Lambda functions. A simple CLI lets you mock AWS Lambda and specify replies
|
29
|
+
for specific function as well as simulate AWS Lambda framework failures.
|
30
|
+
email: quest@lysator.liu.se
|
31
|
+
executables:
|
32
|
+
- faux-lambda
|
33
|
+
extensions: []
|
34
|
+
extra_rdoc_files: []
|
35
|
+
files:
|
36
|
+
- ".gitignore"
|
37
|
+
- Gemfile
|
38
|
+
- Gemfile.lock
|
39
|
+
- README.md
|
40
|
+
- bin/faux-lambda
|
41
|
+
- faux-lambda.gemspec
|
42
|
+
- lib/faux_lambda/version.rb
|
43
|
+
homepage: https://github.com/bittrance/faux-lambda
|
44
|
+
licenses:
|
45
|
+
- MIT
|
46
|
+
metadata: {}
|
47
|
+
post_install_message:
|
48
|
+
rdoc_options: []
|
49
|
+
require_paths:
|
50
|
+
- lib
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: 2.0.0
|
56
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
requirements: []
|
62
|
+
rubyforge_project:
|
63
|
+
rubygems_version: 2.6.13
|
64
|
+
signing_key:
|
65
|
+
specification_version: 4
|
66
|
+
summary: faux-lambda provides a simple tool to mock AWS Lambda endpoint
|
67
|
+
test_files: []
|