Method: Jets::AwsInfo#s3_bucket

Defined in:
lib/jets/aws_info.rb

#s3_bucketObject



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/jets/aws_info.rb', line 72

def s3_bucket
  return "fake-test-s3-bucket" if Jets.env.test?
  return @@s3_bucket unless @@s3_bucket == BUCKET_DOES_NOT_YET_EXIST

  resp = cfn.describe_stacks(stack_name: Jets::Naming.parent_stack_name)
  stack = resp.stacks.first
  output = stack["outputs"].find { |o| o["output_key"] == "S3Bucket" }
  @@s3_bucket = output["output_value"] # s3_bucket
rescue Exception => e
  # When user uses Jets::Application.default_iam_policy in their config/application.rb
  # it looks up the s3 bucket for the iam policy, but the project name has
  # not been loaded in the config yet.  We do some trickery with loading
  # the config twice in Application#load_app_config
  # The first load will result in a Aws::CloudFormation::Errors::ValidationError
  # since the Jets::Naming.parent_stack_name has not been properly set yet.
  #
  # Rescuing all exceptions in case there are other exceptions dont know about yet
  # Here are the known ones: Aws::CloudFormation::Errors::ValidationError, Aws::CloudFormation::Errors::InvalidClientTokenId
  BUCKET_DOES_NOT_YET_EXIST
end