addy_lambda 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.travis.yml +6 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +22 -0
- data/Gemfile.lock +135 -0
- data/LICENSE.txt +21 -0
- data/README.md +73 -0
- data/Rakefile +10 -0
- data/addy_lambda.gemspec +31 -0
- data/deleteme.rb +6 -0
- data/lib/addy_lambda/aws.rb +16 -0
- data/lib/addy_lambda/common.rb +129 -0
- data/lib/addy_lambda/version.rb +3 -0
- data/lib/addy_lambda.rb +10 -0
- metadata +90 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a40fe7dd18f9436441daacde8ea4ea2a6d0ccfd3878a9d2b03e00e7a76c0d8ce
|
4
|
+
data.tar.gz: a8a52aeeafbd076c27b1875cb94d8602eea09272f5f28449e937a8ff581d2d9e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 95519ec57cb521f6e9f8cca6ea1ebaeb9a3a72f55cbc52a67d657a11853ef953096df74512cf6e4bd03b384d1813144467a71ff5c21a4290df451715ad1f2653
|
7
|
+
data.tar.gz: 15db8292c1ea02d3f9868d914dfd2fa381a09dd4bc62a47068fe22c7551f941b6f6676ee47599de36857756c3fa33fca3ab3f9b998b81b7d9bd501e809c02d1c
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at alon@sabi.me. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [https://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: https://contributor-covenant.org
|
74
|
+
[version]: https://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
# Specify your gem's dependencies in addy_lambda.gemspec
|
4
|
+
gemspec
|
5
|
+
|
6
|
+
gem 'aws-sdk-lambda'
|
7
|
+
gem 'aws-sdk-s3'
|
8
|
+
gem 'aws-sdk-sns'
|
9
|
+
gem 'rake', '~> 12.0'
|
10
|
+
|
11
|
+
group :test do
|
12
|
+
gem 'webmock'
|
13
|
+
end
|
14
|
+
|
15
|
+
group :development do
|
16
|
+
gem 'debase'
|
17
|
+
gem 'dotenv'
|
18
|
+
gem 'minitest'
|
19
|
+
gem 'pry'
|
20
|
+
gem 'ruby-debug-ide'
|
21
|
+
gem 'solargraph'
|
22
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,135 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
addy_lambda (0.1.0)
|
5
|
+
aws-sdk-ssm
|
6
|
+
thor
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
addressable (2.8.0)
|
12
|
+
public_suffix (>= 2.0.2, < 5.0)
|
13
|
+
ast (2.4.2)
|
14
|
+
aws-eventstream (1.2.0)
|
15
|
+
aws-partitions (1.534.0)
|
16
|
+
aws-sdk-core (3.122.1)
|
17
|
+
aws-eventstream (~> 1, >= 1.0.2)
|
18
|
+
aws-partitions (~> 1, >= 1.525.0)
|
19
|
+
aws-sigv4 (~> 1.1)
|
20
|
+
jmespath (~> 1.0)
|
21
|
+
aws-sdk-kms (1.52.0)
|
22
|
+
aws-sdk-core (~> 3, >= 3.122.0)
|
23
|
+
aws-sigv4 (~> 1.1)
|
24
|
+
aws-sdk-lambda (1.76.0)
|
25
|
+
aws-sdk-core (~> 3, >= 3.122.0)
|
26
|
+
aws-sigv4 (~> 1.1)
|
27
|
+
aws-sdk-s3 (1.109.0)
|
28
|
+
aws-sdk-core (~> 3, >= 3.122.0)
|
29
|
+
aws-sdk-kms (~> 1)
|
30
|
+
aws-sigv4 (~> 1.4)
|
31
|
+
aws-sdk-sns (1.49.0)
|
32
|
+
aws-sdk-core (~> 3, >= 3.122.0)
|
33
|
+
aws-sigv4 (~> 1.1)
|
34
|
+
aws-sdk-ssm (1.124.0)
|
35
|
+
aws-sdk-core (~> 3, >= 3.122.0)
|
36
|
+
aws-sigv4 (~> 1.1)
|
37
|
+
aws-sigv4 (1.4.0)
|
38
|
+
aws-eventstream (~> 1, >= 1.0.2)
|
39
|
+
backport (1.2.0)
|
40
|
+
benchmark (0.2.0)
|
41
|
+
coderay (1.1.3)
|
42
|
+
crack (0.4.5)
|
43
|
+
rexml
|
44
|
+
debase (0.2.4.1)
|
45
|
+
debase-ruby_core_source (>= 0.10.2)
|
46
|
+
debase-ruby_core_source (0.10.13)
|
47
|
+
diff-lcs (1.4.4)
|
48
|
+
dotenv (2.7.6)
|
49
|
+
e2mmap (0.1.0)
|
50
|
+
hashdiff (1.0.1)
|
51
|
+
jaro_winkler (1.5.4)
|
52
|
+
jmespath (1.4.0)
|
53
|
+
kramdown (2.3.1)
|
54
|
+
rexml
|
55
|
+
kramdown-parser-gfm (1.1.0)
|
56
|
+
kramdown (~> 2.0)
|
57
|
+
method_source (1.0.0)
|
58
|
+
mini_portile2 (2.6.1)
|
59
|
+
minitest (5.14.4)
|
60
|
+
nokogiri (1.12.5)
|
61
|
+
mini_portile2 (~> 2.6.1)
|
62
|
+
racc (~> 1.4)
|
63
|
+
parallel (1.21.0)
|
64
|
+
parser (3.0.3.2)
|
65
|
+
ast (~> 2.4.1)
|
66
|
+
pry (0.14.1)
|
67
|
+
coderay (~> 1.1)
|
68
|
+
method_source (~> 1.0)
|
69
|
+
public_suffix (4.0.6)
|
70
|
+
racc (1.6.0)
|
71
|
+
rainbow (3.0.0)
|
72
|
+
rake (12.3.3)
|
73
|
+
regexp_parser (2.2.0)
|
74
|
+
reverse_markdown (2.1.1)
|
75
|
+
nokogiri
|
76
|
+
rexml (3.2.5)
|
77
|
+
rubocop (1.23.0)
|
78
|
+
parallel (~> 1.10)
|
79
|
+
parser (>= 3.0.0.0)
|
80
|
+
rainbow (>= 2.2.2, < 4.0)
|
81
|
+
regexp_parser (>= 1.8, < 3.0)
|
82
|
+
rexml
|
83
|
+
rubocop-ast (>= 1.12.0, < 2.0)
|
84
|
+
ruby-progressbar (~> 1.7)
|
85
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
86
|
+
rubocop-ast (1.14.0)
|
87
|
+
parser (>= 3.0.1.1)
|
88
|
+
ruby-debug-ide (0.7.3)
|
89
|
+
rake (>= 0.8.1)
|
90
|
+
ruby-progressbar (1.11.0)
|
91
|
+
solargraph (0.44.2)
|
92
|
+
backport (~> 1.2)
|
93
|
+
benchmark
|
94
|
+
bundler (>= 1.17.2)
|
95
|
+
diff-lcs (~> 1.4)
|
96
|
+
e2mmap
|
97
|
+
jaro_winkler (~> 1.5)
|
98
|
+
kramdown (~> 2.3)
|
99
|
+
kramdown-parser-gfm (~> 1.1)
|
100
|
+
parser (~> 3.0)
|
101
|
+
reverse_markdown (>= 1.0.5, < 3)
|
102
|
+
rubocop (>= 0.52)
|
103
|
+
thor (~> 1.0)
|
104
|
+
tilt (~> 2.0)
|
105
|
+
yard (~> 0.9, >= 0.9.24)
|
106
|
+
thor (1.1.0)
|
107
|
+
tilt (2.0.10)
|
108
|
+
unicode-display_width (2.1.0)
|
109
|
+
webmock (3.14.0)
|
110
|
+
addressable (>= 2.8.0)
|
111
|
+
crack (>= 0.3.2)
|
112
|
+
hashdiff (>= 0.4.0, < 2.0.0)
|
113
|
+
webrick (1.7.0)
|
114
|
+
yard (0.9.27)
|
115
|
+
webrick (~> 1.7.0)
|
116
|
+
|
117
|
+
PLATFORMS
|
118
|
+
ruby
|
119
|
+
|
120
|
+
DEPENDENCIES
|
121
|
+
addy_lambda!
|
122
|
+
aws-sdk-lambda
|
123
|
+
aws-sdk-s3
|
124
|
+
aws-sdk-sns
|
125
|
+
debase
|
126
|
+
dotenv
|
127
|
+
minitest
|
128
|
+
pry
|
129
|
+
rake (~> 12.0)
|
130
|
+
ruby-debug-ide
|
131
|
+
solargraph
|
132
|
+
webmock
|
133
|
+
|
134
|
+
BUNDLED WITH
|
135
|
+
2.1.4
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2021 alon
|
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
|
13
|
+
all 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
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
# AddyLambda
|
2
|
+
|
3
|
+
The purpose of this gem, is to make common functionality for Lambdas be available across all of our Lambda implementaitons.
|
4
|
+
|
5
|
+
Things like:
|
6
|
+
- calling API endpoints
|
7
|
+
- Posting to slack
|
8
|
+
- Getting a JWT token
|
9
|
+
- Sending an email
|
10
|
+
- etc ..
|
11
|
+
|
12
|
+
This would allow us to be consistent with our approach to those common functions without duplicating code.
|
13
|
+
|
14
|
+
## Installation
|
15
|
+
|
16
|
+
Add this line to your application's Gemfile:
|
17
|
+
|
18
|
+
```ruby
|
19
|
+
gem 'addy_lambda'
|
20
|
+
```
|
21
|
+
|
22
|
+
And then execute:
|
23
|
+
|
24
|
+
$ bundle install
|
25
|
+
|
26
|
+
Or install it yourself as:
|
27
|
+
|
28
|
+
$ gem install addy_lambda
|
29
|
+
|
30
|
+
## Usage
|
31
|
+
|
32
|
+
Run the tests:
|
33
|
+
```
|
34
|
+
ruby "/home/cabox/workspace/addy_lambda/test/addy_lambda_test.rb"
|
35
|
+
```
|
36
|
+
|
37
|
+
For local development:
|
38
|
+
|
39
|
+
```
|
40
|
+
rake build
|
41
|
+
gem install pkg/addy_lambda-<version>.gem
|
42
|
+
```
|
43
|
+
|
44
|
+
Example usage:
|
45
|
+
|
46
|
+
```
|
47
|
+
require 'addy_lambda'
|
48
|
+
require 'aws-sdk-ssm'
|
49
|
+
|
50
|
+
ssm_client = Aws::SSM::Client.new
|
51
|
+
test= AddyLambda::AWS::get_ssm_value(ssm_client, '/dev/test')
|
52
|
+
|
53
|
+
puts(test)
|
54
|
+
```
|
55
|
+
|
56
|
+
## Development
|
57
|
+
|
58
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
59
|
+
|
60
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
61
|
+
|
62
|
+
## Contributing
|
63
|
+
|
64
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/addy_lambda. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/addy_lambda/blob/master/CODE_OF_CONDUCT.md).
|
65
|
+
|
66
|
+
|
67
|
+
## License
|
68
|
+
|
69
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
70
|
+
|
71
|
+
## Code of Conduct
|
72
|
+
|
73
|
+
Everyone interacting in the AddyLambda project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/addy_lambda/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/addy_lambda.gemspec
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require_relative 'lib/addy_lambda/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = 'addy_lambda'
|
5
|
+
spec.version = AddyLambda::VERSION
|
6
|
+
spec.authors = ['Alon Sabi']
|
7
|
+
spec.email = ['alon@sabi.me']
|
8
|
+
|
9
|
+
spec.summary = 'A GEM for re-usable Lambda common functionalities'
|
10
|
+
spec.description = 'Include this gem in your Lambda code to provide generic functionality, standardize code, and expedite development'
|
11
|
+
spec.homepage = 'https://github.com/InvestIMBY/addy_lambda'
|
12
|
+
spec.license = 'MIT'
|
13
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 2.5.0')
|
14
|
+
|
15
|
+
spec.metadata['allowed_push_host'] = 'https://rubygems.org'
|
16
|
+
|
17
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
18
|
+
spec.metadata['source_code_uri'] = 'https://github.com/InvestIMBY/addy_lambda'
|
19
|
+
spec.metadata['changelog_uri'] = 'https://github.com/InvestIMBY/addy_lambda/changelog'
|
20
|
+
|
21
|
+
# Specify which files should be added to the gem when it is released.
|
22
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
23
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
24
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
25
|
+
end
|
26
|
+
spec.bindir = 'exe'
|
27
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
+
spec.require_paths = ['lib']
|
29
|
+
spec.add_dependency 'aws-sdk-ssm'
|
30
|
+
spec.add_dependency 'thor'
|
31
|
+
end
|
data/deleteme.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module AddyLambda
|
4
|
+
# Common functionality for AWS related activities
|
5
|
+
class AWS
|
6
|
+
# ssm_client = Aws::SSM::Client.new
|
7
|
+
def self.get_ssm_value(ssm_client, path)
|
8
|
+
request = {
|
9
|
+
name: path,
|
10
|
+
with_decryption: true
|
11
|
+
}
|
12
|
+
response = ssm_client.get_parameter(request)
|
13
|
+
response.parameter.value
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,129 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'aws-sdk-lambda'
|
3
|
+
|
4
|
+
module AddyLambda
|
5
|
+
# Generic methods such as logging, error handling HTTP requests etc.
|
6
|
+
class Common
|
7
|
+
def self.generic_log(logger, event, context)
|
8
|
+
logger.debug('## EVENT')
|
9
|
+
logger.debug(event.inspect)
|
10
|
+
logger.debug('## CONTEXT')
|
11
|
+
logger.debug(context.inspect)
|
12
|
+
end
|
13
|
+
|
14
|
+
# sns = Aws::SNS::Resource.new(region: region)
|
15
|
+
def self.handle_error(sns, logger, error, context)
|
16
|
+
region = context.invoked_function_arn.split(':')[3]
|
17
|
+
aws_account_id = context.invoked_function_arn.split(':')[4]
|
18
|
+
|
19
|
+
err_msg = get_error_json(context, error)
|
20
|
+
logger.error(err_msg)
|
21
|
+
|
22
|
+
topic = sns.topic("arn:aws:sns:#{region}:#{aws_account_id}:system-errors")
|
23
|
+
topic.publish(message: err_msg)
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.handle_error_and_raise(sns, logger, error, context)
|
27
|
+
handle_error(sns, logger, error, context)
|
28
|
+
raise error
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.get_error_json(context, error)
|
32
|
+
{
|
33
|
+
"function_name": context.function_name,
|
34
|
+
"errorType": error.class,
|
35
|
+
"errorMessage": error.message,
|
36
|
+
"stackTrace": error.backtrace,
|
37
|
+
"log_group_name": context.log_group_name,
|
38
|
+
"log_stream_name": context.log_stream_name,
|
39
|
+
"request id": context.aws_request_id
|
40
|
+
}.to_json
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.raise_error_description(description)
|
44
|
+
raise StandardError, description
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.enable_scout_apm
|
48
|
+
return unless ENV['SCOUT_MONITOR'] == 'true'
|
49
|
+
|
50
|
+
require 'scout_apm'
|
51
|
+
ScoutApm::Agent.instance.install
|
52
|
+
end
|
53
|
+
|
54
|
+
# Lambda client can be obtained by running: lambda_client = Aws::Lambda::Client.new
|
55
|
+
def self.post_slack_message(lambda_client, channel, message, emoji = ':tada', unfurl_links: false)
|
56
|
+
input_params = {
|
57
|
+
'user' => 'Signature Request',
|
58
|
+
'channel' => channel,
|
59
|
+
'message' => message,
|
60
|
+
'emoji' => emoji,
|
61
|
+
'unfurl_links' => unfurl_links
|
62
|
+
}
|
63
|
+
response_body = invoke_lambda(lambda_client, 'slack-client', input_params)
|
64
|
+
return response_body unless response_body.key?('error')
|
65
|
+
|
66
|
+
logger.error(response_body['error'])
|
67
|
+
end
|
68
|
+
|
69
|
+
def self.invoke_lambda(lambda_client, function_name, payload)
|
70
|
+
resp = lambda_client.invoke({
|
71
|
+
function_name: function_name,
|
72
|
+
invocation_type: 'RequestResponse',
|
73
|
+
payload: payload.to_json
|
74
|
+
})
|
75
|
+
valid_json?(resp.payload.string)
|
76
|
+
response_obj = JSON.parse(resp.payload.string)
|
77
|
+
valid_json?(resp.payload.string) ? JSON.parse(response_obj['body']) : resp.payload.string
|
78
|
+
end
|
79
|
+
|
80
|
+
def self.get_request(url, params = nil, headers = nil)
|
81
|
+
uri = URI(url)
|
82
|
+
uri.query = URI.encode_www_form(params) if params
|
83
|
+
request = Net::HTTP::Get.new(uri.request_uri)
|
84
|
+
response = http_request(request, uri, headers)
|
85
|
+
end
|
86
|
+
|
87
|
+
def self.delete_request(url, headers = nil)
|
88
|
+
uri = URI(url)
|
89
|
+
request = Net::HTTP::Delete.new(uri.request_uri)
|
90
|
+
http_request(request, uri, headers)
|
91
|
+
end
|
92
|
+
|
93
|
+
def self.post_request(url, params = nil, headers = nil)
|
94
|
+
uri = URI(url)
|
95
|
+
request = Net::HTTP::Post.new(uri.request_uri)
|
96
|
+
request.set_form_data(params) if params
|
97
|
+
http_request(request, uri, headers)
|
98
|
+
end
|
99
|
+
|
100
|
+
def self.http_request(request, uri, headers)
|
101
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
102
|
+
http.use_ssl = true
|
103
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
104
|
+
headers&.each { |header, value| request[header] = value }
|
105
|
+
response = http.request(request)
|
106
|
+
parse_response(response)
|
107
|
+
end
|
108
|
+
|
109
|
+
def self.parse_response(response)
|
110
|
+
response_body = valid_json?(response.body) ? JSON.parse(response.body) : response.body
|
111
|
+
return response_body if response.is_a?(Net::HTTPSuccess)
|
112
|
+
|
113
|
+
raise_error_description(response_body['error_description'])
|
114
|
+
rescue JSON::ParserError => e
|
115
|
+
raise_error_description(e.message)
|
116
|
+
end
|
117
|
+
|
118
|
+
def self.logger
|
119
|
+
@logger ||= Logger.new($stdout).tap { |logger| logger.level = ENV['LOG_LEVEL'].to_i }
|
120
|
+
end
|
121
|
+
|
122
|
+
def self.valid_json?(json)
|
123
|
+
JSON.parse(json)
|
124
|
+
true
|
125
|
+
rescue JSON::ParserError
|
126
|
+
false
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
data/lib/addy_lambda.rb
ADDED
metadata
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: addy_lambda
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Alon Sabi
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-12-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: aws-sdk-ssm
|
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: thor
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: Include this gem in your Lambda code to provide generic functionality,
|
42
|
+
standardize code, and expedite development
|
43
|
+
email:
|
44
|
+
- alon@sabi.me
|
45
|
+
executables: []
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- ".gitignore"
|
50
|
+
- ".travis.yml"
|
51
|
+
- CODE_OF_CONDUCT.md
|
52
|
+
- Gemfile
|
53
|
+
- Gemfile.lock
|
54
|
+
- LICENSE.txt
|
55
|
+
- README.md
|
56
|
+
- Rakefile
|
57
|
+
- addy_lambda.gemspec
|
58
|
+
- deleteme.rb
|
59
|
+
- lib/addy_lambda.rb
|
60
|
+
- lib/addy_lambda/aws.rb
|
61
|
+
- lib/addy_lambda/common.rb
|
62
|
+
- lib/addy_lambda/version.rb
|
63
|
+
homepage: https://github.com/InvestIMBY/addy_lambda
|
64
|
+
licenses:
|
65
|
+
- MIT
|
66
|
+
metadata:
|
67
|
+
allowed_push_host: https://rubygems.org
|
68
|
+
homepage_uri: https://github.com/InvestIMBY/addy_lambda
|
69
|
+
source_code_uri: https://github.com/InvestIMBY/addy_lambda
|
70
|
+
changelog_uri: https://github.com/InvestIMBY/addy_lambda/changelog
|
71
|
+
post_install_message:
|
72
|
+
rdoc_options: []
|
73
|
+
require_paths:
|
74
|
+
- lib
|
75
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: 2.5.0
|
80
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
requirements: []
|
86
|
+
rubygems_version: 3.1.6
|
87
|
+
signing_key:
|
88
|
+
specification_version: 4
|
89
|
+
summary: A GEM for re-usable Lambda common functionalities
|
90
|
+
test_files: []
|