简体   繁体   中英

copy files from s3 into redshift vai IAM roles

Not sure if this is the right question for this forum but how do you use COPY in Redshift to upload a file in S3 and use an IAM role instead of access keys. I see the syntax is this:

copy tablea
from 's3 path'
credentials 'aws_access_key_id=<access-key-id>;aws_secret_access_key=<secret-access-key>'

but what if you wanted to use IAM roles to authenticate?

You should call the COPY commnad with temporary credentials based on your IAM Role.

You can get the temporary credentials for the current IAM role via the sdk. For example in ruby:

require 'aws-sdk'

sts = Aws::STS::Client.new(region: 'us-east-1')
session= sts.get_session_token
access_key_id = session.credentials.access_key_id
secret_access_key = session.credentials.secret_access_key
session_token = session.credentials.session_token

Once you have the temporary credentials you can call the COPY command with the following syntax:

 copy table_name
 from 's3://objectpath'
 credentials 'aws_access_key_id=<temporary-access-key-id>;aws_secret_access_key=<temporary-secret-access-key>;token=<temporary-token>';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM