architect-functions 0.1.0 → 0.2.0
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 +4 -4
- data/lib/architect/events.rb +21 -0
- data/lib/architect/http.rb +10 -0
- data/lib/architect/queues.rb +25 -0
- data/lib/architect/reflect.rb +23 -0
- data/lib/architect/tables.rb +13 -0
- data/lib/architect/ws.rb +24 -0
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9f531e06892a92e481e3e7673ead66d00f142e7523ef919c0dfbceb4ff46ddb3
|
4
|
+
data.tar.gz: 7588bf9ee9820135d97aece411821c3855c604fe95d5488f745f19b35d1c0b03
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 826d0372f2767e74b815bcc9d6d67521225184a34fe448ae7c0a135a0ab494c6c34f1724eae46c9dc6ecc9994ed6e57d2bd038cb1d35f93e6b496992bc2167b7
|
7
|
+
data.tar.gz: 1e4ae45aa9f2700085bb6e7a307e9737c25b87793c39ce8964d17138ad903dcaf9568337db5302097ef56fe99cd60ca4e67927e27e5ac833eb684275b0119b19
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'aws-sdk-sns'
|
2
|
+
require 'json'
|
3
|
+
require_relative 'reflect'
|
4
|
+
|
5
|
+
module Arc
|
6
|
+
module Events
|
7
|
+
##
|
8
|
+
# publish a message to an SNS Topic
|
9
|
+
#
|
10
|
+
def self.publish(params)
|
11
|
+
name = params[:name]
|
12
|
+
payload = params[:payload]
|
13
|
+
raise ArgumentError, 'missing name' unless name
|
14
|
+
raise ArgumentError, 'missing payload' unless payload
|
15
|
+
arc = Arc.reflect
|
16
|
+
arn = arc['events'][name]
|
17
|
+
sns = Aws::SNS::Client.new
|
18
|
+
sns.publish :topic_arn=> arn, :message=> JSON.generate(payload)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'aws-sdk-sqs'
|
2
|
+
require 'json'
|
3
|
+
require_relative 'reflect'
|
4
|
+
|
5
|
+
module Arc
|
6
|
+
module Queues
|
7
|
+
##
|
8
|
+
# publish a message to an SQS Queue
|
9
|
+
#
|
10
|
+
def self.publish(params)
|
11
|
+
name = params[:name]
|
12
|
+
payload = params[:payload]
|
13
|
+
raise ArgumentError, 'missing name' unless name
|
14
|
+
raise ArgumentError, 'missing payload' unless payload
|
15
|
+
arc = Arc.reflect
|
16
|
+
url = arc['queues'][name]
|
17
|
+
sqs = Aws::SQS::Client.new
|
18
|
+
sqs.send_message({
|
19
|
+
queue_url: url,
|
20
|
+
delay_seconds: 0,
|
21
|
+
message_body: JSON.generate(payload)
|
22
|
+
})
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'aws-sdk-ssm'
|
2
|
+
|
3
|
+
module Arc
|
4
|
+
##
|
5
|
+
# Returns a hash of the current Architect runtime resources
|
6
|
+
#
|
7
|
+
def self.reflect
|
8
|
+
client = Aws::SSM::Client.new
|
9
|
+
res = client.get_parameters_by_path({
|
10
|
+
path: '/' + ENV['ARC_CLOUDFORMATION'],
|
11
|
+
recursive: true,
|
12
|
+
})
|
13
|
+
res.parameters.reduce({}) do |result, param|
|
14
|
+
bits = param.name.split('/').reject { |c| c.empty? }
|
15
|
+
type = bits[1] # events, queues, tables, ws, static
|
16
|
+
key = bits[2] # the name in the .arc file
|
17
|
+
val = param.value # the name generated by cfn
|
18
|
+
result[type] = {} unless result.key?(type)
|
19
|
+
result[type][key] = val
|
20
|
+
result
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/architect/ws.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'aws-sdk-apigateway'
|
2
|
+
require 'json'
|
3
|
+
require_relative 'reflect'
|
4
|
+
|
5
|
+
module Arc
|
6
|
+
module WS
|
7
|
+
##
|
8
|
+
# send a message to a web socket
|
9
|
+
#
|
10
|
+
def self.send(params)
|
11
|
+
id = params[:id]
|
12
|
+
payload = params[:payload]
|
13
|
+
raise ArgumentError, 'missing id' unless id
|
14
|
+
raise ArgumentError, 'missing payload' unless payload
|
15
|
+
arc = Arc.reflect
|
16
|
+
url = arc['ws']['https']
|
17
|
+
api = Aws::ApiGatewayManagementApi::Client.new({endpoint: url})
|
18
|
+
api.postToConnection({
|
19
|
+
connection_id: id,
|
20
|
+
data: JSON.stringify(payload)
|
21
|
+
})
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: architect-functions
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian LeRoux
|
@@ -10,13 +10,19 @@ bindir: bin
|
|
10
10
|
cert_chain: []
|
11
11
|
date: 2019-01-26 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description: Runtime helpers for Architect
|
13
|
+
description: Runtime helpers for AWS Lambda functions provisioned with Architect
|
14
14
|
email: b@brian.io
|
15
15
|
executables: []
|
16
16
|
extensions: []
|
17
17
|
extra_rdoc_files: []
|
18
18
|
files:
|
19
|
+
- lib/architect/events.rb
|
19
20
|
- lib/architect/functions.rb
|
21
|
+
- lib/architect/http.rb
|
22
|
+
- lib/architect/queues.rb
|
23
|
+
- lib/architect/reflect.rb
|
24
|
+
- lib/architect/tables.rb
|
25
|
+
- lib/architect/ws.rb
|
20
26
|
homepage: http://rubygems.org/gems/architect-functions
|
21
27
|
licenses:
|
22
28
|
- Apache-2.0
|