Class: Jets::AwsInfo
- Inherits:
-
Object
- Object
- Jets::AwsInfo
- Extended by:
- Memoist
- Includes:
- AwsServices
- Defined in:
- lib/jets/aws_info.rb
Instance Method Summary collapse
-
#account ⇒ Object
aws sts get-caller-identity.
- #region ⇒ Object
- #test? ⇒ Boolean
Methods included from AwsServices
#cfn, #lambda, #logs, #s3, #s3_resource, #stack_exists?, #stack_in_progress?, #sts
Instance Method Details
#account ⇒ Object
aws sts get-caller-identity
30 31 32 33 |
# File 'lib/jets/aws_info.rb', line 30 def account return '123456789' if test? sts.get_caller_identity.account end |
#region ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/jets/aws_info.rb', line 7 def region return 'us-east-1' if test? region = nil # First try to get it from the ~/.aws/config region = `aws configure get region`.strip rescue nil return region if region # Second try the metadata endpoint, should be available on AWS Lambda environment # https://stackoverflow.com/questions/4249488/find-region-from-within-an-ec2-instance begin az = `curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone` region = az.strip.chop # remove last char rescue end return region if region ENV['JETS_AWS_REGION'] || 'us-east-1' # default if all else fails end |
#test? ⇒ Boolean
36 37 38 |
# File 'lib/jets/aws_info.rb', line 36 def test? ENV['TEST'] || ENV['CIRCLECI'] end |