download_from_s3

in lib/instance_agent/plugins/codedeploy/command_executor.rb [241:276]


        def download_from_s3(deployment_spec, bucket, key, version, etag)
          log(:info, "Downloading artifact bundle from bucket '#{bucket}' and key '#{key}', version '#{version}', etag '#{etag}'")
          options = s3_options()
          s3 = Aws::S3::Client.new(options)
          ProcessManager::Log.info("s3 client configuration below:")
          ProcessManager::Log.info(s3.config)

          File.open(artifact_bundle(deployment_spec), 'wb') do |file|

          begin
            if !version.nil?
              object = s3.get_object({:bucket => bucket, :key => key, :version_id => version}, :target => file)
            else
              object = s3.get_object({:bucket => bucket, :key => key}, :target => file)
            end
          rescue Seahorse::Client::NetworkingError => e
            if e.message.include? "unable to connect to"
              if InstanceAgent::Config.config[:use_fips_mode]
                raise $!, "#{$!}. Check that Fips exists in #{options[:region]}. Or, try using s3 endpoint override.", $!.backtrace
              else
                raise $!, "#{$!}. Try using s3 endpoint override.", $!.backtrace
              end
            else
              raise
            end
          end

            if(!etag.nil? && !(etag.gsub(/"/,'').eql? object.etag.gsub(/"/,'')))
              msg = "Expected deployment artifact bundle etag #{etag} but was actually #{object.etag}"
              log(:error, msg)
              raise RuntimeError, msg
            end
          end
          log(:info, "Download complete from bucket #{bucket} and key #{key}")
        end