S3::Object.new(bucket_name, key).put(body:’…’, content_type: ‘…')
Aws::S3::Client
, right?
my.bucket
I have 2 profiles in my ~/.aws/credentials
that are completely separate AWS accounts (one is my personal, one for my company)
I created an ran this script. I do not have a bucket named reports
in my personal AWS account, but this puts the first object in my company account’s report
bucket
require 'rubygems'
require 'aws-sdk'
creds1 = Aws::SharedCredentials.new(profile_name: 'erik')
s3_client1 = Aws::S3::Client.new(region: 'us-east-1', credentials: creds1)
s3_resource1 = Aws::S3::Resource.new(client: s3_client1)
s3_bucket1 = s3_resource1.bucket('reports')
object = s3_bucket1.objects.first
p object
instance = Aws::EC2::Resource.new.instances.first
old_timestamp = instance.password_data.timestamp
instance.reboot
instance.wait_until { |i| i.password_data.timestamp != old_timestamp }
response
in the block was nil on at least the first attempt, which seemed odd
... do |attempts, response|
puts "#{attempts}; timestamp this time: #{response.password_data.timestamp}"
end
nil
proc = Proc.new do |attempts, response|
logger.debug "Waiting for password data timestamp to be newer", {pwd_timestamp: instance.password_data.timestamp, newer_than: since}
end
instance.wait_until(max_attempts: 30, delay: 10, before_wait: proc) { |i| i.password_data.timestamp != since }
i
is an Instance resource
w.max_attempts = 15
w.interval = 0
w.before_attempt do |a, resp|
pause_exponentially n
logger.debug "Waiting for password...", {instance_id: id, attempt_count: a}
end
def pause_exponentially(n, seed=2, exp=1.4)
sleep(seed * (exp ** n))
end
There is not an accessible way to change the default waiter value currently. Currently, the waiter provider is a private interface, and is subject to change. If you are comfortable poking into something that may change in the future, you could do the following:
EC2::Client.waiters.instance_variable_get("@waiters")[:instance_running][:delay] = 20
I’d be open to suggestions on how to make this more flexible, until then, I left the interfaces marked @api private.
exists?
method...? v2 does not. Aws::EC2::Instance does. the API reference doesn't show either Instance or Image to have an attribute that sounds like 'exists' other than maybe state
on Instance.
aws-sdk
gem to make the API calls.
Aws.config[:dynamodb][:stub_responses] = {put_item: 'ProvisionedThroughputExceededException’}
allow_any_instance_of(Aws::DynamoDB::Client).to receive(:put_item).
with(hash_including(table_name:'my-table').
and_raise(Aws::DynamoDB::Errors::ProvisionedThroughputExceededException)
Aws::DynamoDB::Errors::ProvisionedThroughputExceededException
. I kept getting an ArgumentError returned (ArgumentError: wrong number of arguments (0 for 2)
). I finally figured out that this had to do with the constructor of the error. Perhaps, this is expected, but I didn’t realize it. Setting nil
for both params made this work.allow_any_instance_of(Aws::DynamoDB::Client).to
receive(:put_item).
with(hash_including(table_name: "Users")).
and_raise(Aws::DynamoDB::Errors::ProvisionedThroughputExceededException.new(nil, nil))