读取S3对象(csv文件)的内容

时间:2019-05-17 07:28:27

标签: ruby amazon-web-services amazon-s3

以下是我正在尝试使用Ruby在AWS中进行的操作

  1. 连接到Athena并在其中一个表上执行查询, 结果将作为对象(.csv)存储在s3存储桶中
  2. 检查文件是否存储在特定存储桶中
  3. 读取文件内容

到目前为止,我能够完成第1步和第2步。我陷入了第3步。想知道如何继续执行此步骤?

require 'aws-sdk'
require 'aws-sdk-s3'

# conn = Athens::Connection.new(region: 'ap-southeast-2')
athena = Aws::Athena::Client.new(region: 'ap-southeast-2')
response = athena.start_query_execution({
    query_string: "Select * from test_table",
    query_execution_context: {
        database: "test_database",
    },
    result_configuration: {
        output_location: "s3://test",
        encryption_configuration: {
            encryption_option: "SSE_S3", # required, accepts SSE_S3, SSE_KMS, CSE_KMS
            kms_key: "String",
        },
    },
    work_group: "primary"
})
puts response[:query_execution_id]
sleep(300)
file = response[:query_execution_id]+ ".csv"
puts file.class


s3 = Aws:: S3:: Resource.new(region: 'ap-southeast-2')
bucket_exists = s3.bucket('test').exists ?
    puts bucket_exists

bucket = s3.bucket('badariathena')


if bucket.object(file).exists ?
    puts "File present"
else
    puts "File not present"
end

0 个答案:

没有答案