Module: Smash::CloudPowers::AwsResources
- Included in:
- Smash::CloudPowers, Resource, Storage, Synapse::Broadcast, Synapse::Pipe, Synapse::Queue, Synapse::Queue::Board
- Defined in:
- lib/cloud_powers/aws_resources.rb
Instance Method Summary collapse
-
#ec2(opts = {}) ⇒ Object
Get or create an EC2 client and cache that client so that a Context is more well tied together.
-
#image(name, opts = {}) ⇒ Object
Get an image using a name and filters functionality from EC2.
-
#kinesis(opts = {}) ⇒ Object
Get or create an Kinesis client and cache that client so that a Context is more well tied together.
-
#queue_poller(url:, client: sqs) ⇒ Object
Create a QueuePoller for an already created SQS Queue (CloudPowers::Synapse::Board).
-
#region ⇒ Object
Get the region from the environment/context or use a default region for AWS API calls.
-
#s3(opts = {}) ⇒ Object
Get or create an S3 client and cache that client so that a Context is more well tied together.
-
#sns(opts = {}) ⇒ Object
Get or create an SNS client and cache that client so that a Context is more well tied together Parameters * opts
Hash
* * stub_responses: defaulted to false but it can be overriden with the desired responses for local testing * * region: defaulted to use the ‘#region()` method * * AWS::Credentials object, which will also scour the context and environment for your keys. -
#sqs(opts = {}) ⇒ Object
Get or create an SQS client and cache that client so that a Context is more well tied together.
Methods included from Zenv
#env_vars, #i_vars, #lsof_cwd, #pid, #proc_cwd, #process_search, #project_root, #project_root=, #ps_cwd, #system_vars, #zfind, #zselect
Methods included from Helpers
#create_logger, #log_file, #logger
Methods included from PathHelp
#common_delimiter, #expand_path, #file_exists?, #file_search, #filename?, #job_exist?, #job_path, #job_require_path, #path_search, #paths_gcd, #paths_lcd, #to_path, #to_pathname, #to_realpath, #touch, #zlib_path
Methods included from LogicHelp
#attr_map, #called_from, #i_var_hash, #instance_attr_accessor, #smart_retry, #update_message_body, #wait_until
Methods included from LangHelp
#deep_modify_keys_with, #extract!, #find_and_remove, #format_error_message, #from_json, #modify_keys_with, #to_basic_hash, #to_camel, #to_hyph, #to_i_var, #to_pascal, #to_ruby_file_name, #to_snake, #valid_json?, #valid_url?
Methods included from Auth
Instance Method Details
#ec2(opts = {}) ⇒ Object
Get or create an EC2 client and cache that client so that a Context is more well tied together
Parameters
-
opts
Hash
(optional) -
stub_responses - defaulted to
false
but it can be overriden with the desired responses for local testing
-
-
region - defaulted to use the
#region()
method
-
-
AWS::Credentials object, which will also scour the context and environment for your keys
-
Returns AWS::EC2::Client
Example
images = ec2.describe_images
images.first[:image_id]
# => 'asdf'
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/cloud_powers/aws_resources.rb', line 35 def ec2(opts = {}) config = { stub_responses: false, region: region, credentials: Auth.creds } config = config.merge(opts.select { |k| config.key?(k) }) @ec2 ||= Aws::EC2::Client.new(config) end |
#image(name, opts = {}) ⇒ Object
Get an image using a name and filters functionality from EC2. The name is required but the filter defaults to search for the tag with the key ‘aminame` because this is the key that most Nodes will search for, when they gather an AMI to start with.
Parameters
-
opts [Hash]
-
stub_responses: defaulted to false but it can be overriden with the desired responses for local testing
-
-
region: defaulted to use the ‘#region()` method
-
-
AWS::Credentials object, which will also scour the context and environment for your keys
-
Returns Aws::EC2::Image
58 59 60 61 62 63 64 65 |
# File 'lib/cloud_powers/aws_resources.rb', line 58 def image(name, opts = {}) config = { filters: [{ name: 'tag:aminame', values: [name.to_s] }] } config = config.merge(opts.select { |k| config.key?(k) }) ec2(opts).describe_images(config).images.first end |
#kinesis(opts = {}) ⇒ Object
Get or create an Kinesis client and cache that client so that a Context is more well tied together
Parameters
-
opts
Hash
-
stub_responses: defaulted to false but it can be overriden with the desired responses for local testing
-
-
region: defaulted to use the ‘#region()` method
-
-
AWS::Credentials object, which will also scour the context and environment for your keys
-
Returns AWS::Kinesis client
Example
pipe_to('somePipe') { update_body(status: 'waHoo') } # uses Aws::Kinesis::Client.put_recor()
# => sequence_number: '1676151970'
81 82 83 84 85 86 87 88 89 90 |
# File 'lib/cloud_powers/aws_resources.rb', line 81 def kinesis(opts = {}) config = { stub_responses: false, region: region, credentials: Auth.creds } config = config.merge(opts.select { |k| config.key?(k) }) @kinesis ||= Aws::Kinesis::Client.new(config) end |
#queue_poller(url:, client: sqs) ⇒ Object
Create a QueuePoller for an already created SQS Queue (CloudPowers::Synapse::Board)
Parameters
-
:url
String
- the url for the Queue/Board -
:client
Aws::SQS::Client
Returns Aws::SQS::QueuePoller
Notes
-
this is different from the other methods in here, in that it doesn’t
create an i-var on your class.
105 106 107 |
# File 'lib/cloud_powers/aws_resources.rb', line 105 def queue_poller(url:, client: sqs) Aws::SQS::QueuePoller.new(url, client: client) end |
#region ⇒ Object
Get the region from the environment/context or use a default region for AWS API calls.
Returns String
16 17 18 |
# File 'lib/cloud_powers/aws_resources.rb', line 16 def region zfind(:aws_region) || 'us-west-2' end |
#s3(opts = {}) ⇒ Object
Get or create an S3 client and cache that client so that a Context is more well tied together
Parameters
-
opts
Hash
-
stub_responses: defaulted to false but it can be overriden with the desired responses for local testing
-
-
region: defaulted to use the ‘#region()` method
-
-
AWS::Credentials object, which will also scour the context and environment for your keys
-
Returns AWS::S3 client
Example
expect(s3.head_bucket('exampleBucket')).to be_empty
# passing test
123 124 125 126 127 128 129 130 131 132 |
# File 'lib/cloud_powers/aws_resources.rb', line 123 def s3(opts = {}) config = { stub_responses: false, region: region, credentials: Auth.creds } config = config.merge(opts.select { |k| config.key?(k) }) @s3 ||= Aws::S3::Client.new(config) end |
#sns(opts = {}) ⇒ Object
Get or create an SNS client and cache that client so that a Context is more well tied together Parameters
-
opts
Hash
-
stub_responses: defaulted to false but it can be overriden with the desired responses for local testing
-
-
region: defaulted to use the ‘#region()` method
-
-
AWS::Credentials object, which will also scour the context and environment for your keys
-
Returns AWS::SNS client
Example
create_channel!('testBroadcast') # uses Aws::SNS::Client
# => true
147 148 149 150 151 152 153 154 155 156 |
# File 'lib/cloud_powers/aws_resources.rb', line 147 def sns(opts = {}) config = { stub_responses: false, region: region, credentials: Auth.creds } config = config.merge(opts.select { |k| config.key?(k) }) @sns ||= Aws::SNS::Client.new(config) end |
#sqs(opts = {}) ⇒ Object
Get or create an SQS client and cache that client so that a Context is more well tied together
Parameters
-
opts
Hash
-
stub_responses: defaulted to false but it can be overriden with the desired responses for local testing
-
-
region: defaulted to use the ‘#region()` method
-
-
AWS::Credentials object, which will also scour the context and environment for your keys
-
Returns AWS::SQS client
Example
create_queue('someQueue') # Uses Aws::SQS::Client
171 172 173 174 175 176 177 178 179 |
# File 'lib/cloud_powers/aws_resources.rb', line 171 def sqs(opts = {}) config = { stub_responses: false, credentials: Auth.creds } config = config.merge(opts.select { |k| config.key?(k) }) @sqs ||= Aws::SQS::Client.new(config) end |