addy_lambda 0.1.1 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b6e0c3ac7b853a06d75aed86d86c507c8b26eaa012572ec6e075782fc11c554a
4
- data.tar.gz: dfd63b81d918faed64600bd88cb5e03773697aa2b6aa2fc09898ebb4923c2b59
3
+ metadata.gz: 5e813edb9e46e1f1c6e7af77819d0f5ac1b313b99b0ba0c4d26bb729ba749068
4
+ data.tar.gz: 1fc81b2cfb959e294c46a42abdf11c2c92f1bd6615da4b98de9f9361ad322090
5
5
  SHA512:
6
- metadata.gz: 1ec0bc266dcbeeae6e680437e9172b773ee71856238a1a285d58395883171f585a052614a38b7e05a1f1094b8253b1b0eae57b48cb983995fcb744adf97db959
7
- data.tar.gz: ee662005af9a3efcf3536b3dee8c9db79718d0dc8840fd00756a2cad094c6d1d416cc5f12abdba149b3303d2da978053c75e61940da7fa1aa574c4df83b9046c
6
+ metadata.gz: 490b1703c07468e6d331d83dd0d37013a9ee2d8645cc2ff47686230d02fe2f80c6f74828cfa149f762069ae6a5152553fe45d6e93959fc6ffd88e9f5431485e3
7
+ data.tar.gz: b22cdc6f22d90019eec62d3ff9abaf6b734cd5ef6c89d55a3f0bc3777e3cf09b716f1f0a35884c1b771078d1d07cb83885ef1780f7fe55b20ce1c8f9da1abcba
data/Gemfile.lock CHANGED
@@ -1,7 +1,10 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- addy_lambda (0.1.0)
4
+ addy_lambda (0.1.2)
5
+ aws-sdk-lambda
6
+ aws-sdk-s3
7
+ aws-sdk-sns
5
8
  aws-sdk-ssm
6
9
  thor
7
10
 
data/README.md CHANGED
@@ -33,6 +33,8 @@ Or install it yourself as:
33
33
  - Make your changes
34
34
  - Bump the version in `lib/addy_lambda/version.rb`
35
35
  - Build using `gem build addy_lambda.gemspec`
36
+ - Run (this needs to happen once) `curl -u addydev https://rubygems.org/api/v1/api_key.yaml > ~/.gem/credentials; chmod 0600 ~/.gem/credentials`
37
+ - gem push addy_lambda-<version>.gem
36
38
 
37
39
  ## Usage
38
40
 
Binary file
Binary file
data/addy_lambda.gemspec CHANGED
@@ -26,6 +26,9 @@ Gem::Specification.new do |spec|
26
26
  spec.bindir = 'exe'
27
27
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
28
  spec.require_paths = ['lib']
29
+ spec.add_dependency 'aws-sdk-lambda'
30
+ spec.add_dependency 'aws-sdk-s3'
31
+ spec.add_dependency 'aws-sdk-sns'
29
32
  spec.add_dependency 'aws-sdk-ssm'
30
33
  spec.add_dependency 'thor'
31
34
  end
@@ -51,6 +51,19 @@ module AddyLambda
51
51
  logger.error(response_body['error'])
52
52
  end
53
53
 
54
+ # s3_client = Aws::S3::Client.new
55
+ def self.copy_file_from_s3(s3_client, bucket, key, destination)
56
+ s3_client.get_object({ bucket: bucket, key: key }, target: destination)
57
+ end
58
+
59
+ # s3_client = Aws::S3::Client.new
60
+ def self.save_file_to_s3(s3_client, file_location, bucket, key)
61
+ # Upload
62
+ File.open(file_location, 'rb') do |file|
63
+ s3_client.put_object(bucket: bucket, key: key, body: file)
64
+ end
65
+ end
66
+
54
67
  def self.send_email(lambda_client, recipient_emails, from_name, from_email, subject, content_html)
55
68
  input_params = {
56
69
  'recipient_list' => recipient_emails,
@@ -3,6 +3,8 @@ require 'json'
3
3
  module AddyLambda
4
4
  # Generic methods such as logging, error handling HTTP requests etc.
5
5
  class Common
6
+ VARIABLE_DIRECT = 'direct'.freeze
7
+
6
8
  def self.generic_log(logger, event, context)
7
9
  logger.debug('## EVENT')
8
10
  logger.debug(event.inspect)
@@ -10,6 +12,29 @@ module AddyLambda
10
12
  logger.debug(context.inspect)
11
13
  end
12
14
 
15
+ def self.get_body_as_object(event)
16
+ body_as_object = {}
17
+
18
+ if event.key?('body') and event['body'].is_a? String
19
+ body_as_object = JSON.parse(event['body'])
20
+ elsif event.key?('body')
21
+ body_as_object = event['body']
22
+ end
23
+
24
+ body_as_object
25
+ end
26
+
27
+ def self.get_parameter(event, parameter, type, default_value = nil)
28
+ event_body = get_body_as_object(event)
29
+
30
+ case type
31
+ when VARIABLE_DIRECT
32
+ event_body.fetch(parameter, default_value)
33
+ else
34
+ default_value
35
+ end
36
+ end
37
+
13
38
  # sns = Aws::SNS::Resource.new(region: region)
14
39
  def self.handle_error(sns, logger, error, context)
15
40
  region = context.invoked_function_arn.split(':')[3]
@@ -1,3 +1,3 @@
1
1
  module AddyLambda
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.3'
3
3
  end
metadata CHANGED
@@ -1,15 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: addy_lambda
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alon Sabi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-12-14 00:00:00.000000000 Z
11
+ date: 2022-01-12 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: aws-sdk-lambda
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: aws-sdk-s3
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
+ - !ruby/object:Gem::Dependency
42
+ name: aws-sdk-sns
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
13
55
  - !ruby/object:Gem::Dependency
14
56
  name: aws-sdk-ssm
15
57
  requirement: !ruby/object:Gem::Requirement
@@ -54,8 +96,9 @@ files:
54
96
  - LICENSE.txt
55
97
  - README.md
56
98
  - Rakefile
99
+ - addy_lambda-0.1.0.gem
100
+ - addy_lambda-0.1.1.gem
57
101
  - addy_lambda.gemspec
58
- - deleteme.rb
59
102
  - lib/addy_lambda.rb
60
103
  - lib/addy_lambda/aws.rb
61
104
  - lib/addy_lambda/common.rb
data/deleteme.rb DELETED
@@ -1,15 +0,0 @@
1
- require_relative 'lib/addy_lambda'
2
-
3
- lambda_client = Aws::Lambda::Client.new
4
-
5
- # resp = AddyLambda::AWS.send_email(lambda_client, ['alon@sabi.me', 'alon@addyinvest.com'], 'alon', 'alon@addyinvest.com',
6
- # 'This is the subject', 'This is the content')
7
-
8
- # resp = AddyLambda::AWS.post_slack_message(lambda_client, '@alon', 'This is the mess', ':tada:')
9
-
10
- # pdf_annotate / subscription
11
- resp = AddyLambda::AWS.generate_jwt(lambda_client, AddyLambda::JwtIssuers::ADDY, AddyLambda::JwtAudiences::GENERIC,
12
- 3000, { 'alon' => 'sabi' })
13
- # resp = AddyLambda::AWS.validate_jwt(lambda_client,
14
- # 'eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJhbG9uIjoic2FiaSIsImlzcyI6ImFkZHkiLCJhdWQiOiJnZW5lcmljIiwiaWF0IjoxNjM5NDQxMzk5LCJleHAiOjE2Mzk0NDQzOTl9.jj2OhiEZnJ9s6tamHdc0wGNzlgW3Jwq-S8YquTxe_JWhHuOZKYUhlCM1J1AtaLBqwbnFONCI1geK6cDXIA57lwikh2GcBZGecFfn3hq5IuoSqkhSW-PypTsw2dVCPX-W-qOj6ktbVkTU-d9NvTJJAR4nkJdQMBFtDDgMP_huzxldUjkV9i4ruiebev9blinLuwS_pHIOeqpnTkqRxQ9U6oZscYT8dxHUVoTG03_1dbnnfq3xoBjmBzENz9j2CtZO_fnM96iwqPR4EfxpM7TU7o9NxIzunmN4_Z6Jmjh5yQWpRSp5ItnqQ5N9m6a5bE3NyGDfJh3tVHs7wg3VNqxsLQ')
15
- puts(resp)