当前位置: 动力学知识库 > 问答 > 编程问答 >

java - How to use Redshift COPY with non hard-coded keys

问题描述:

Following is what I tried, but it didn't work. I think the problem is the generated keys are only generated for the scope of EC2 instance. So when Redshift tries to call COPY command with that then its not recognized.

AWSCredentialsProvider credentialProvider = new DefaultAWSCredentialsProviderChain();

return new StringBuilder("COPY ").append(tmpPrefix)

.append(tableName)

.append(" FROM '")

.append(filePath)

.append("' WITH CREDENTIALS 'aws_access_key_id=")

.append(credentialProvider.getCredentials().getAWSAccessKeyId())

.append(";aws_secret_access_key=")

.append(credentialProvider.getCredentials().getAWSSecretKey())

.append("' JSON 'auto' GZIP ACCEPTINVCHARS ' ' TRUNCATECOLUMNS TRIMBLANKS;")

.toString();

Following is the error i got

[Amazon](500310) Invalid operation: S3ServiceException:The AWS Access Key Id you provided does not exist in our records.,Status 403,Error InvalidAccessKeyId....

Any idea how to get this working?

网友答案:

You are using IAM Role ( which creates you set of temporary credentials + token ).

When you execute a COPY command using temp creds (access, secret, token ) you have provide token as well: credentials 'aws_access_key_id=<temporary-access-key-id>;aws_secret_access_key=<temporary-secret-access-key>;token=<temporary-token>';

Take a look at the docs http://docs.aws.amazon.com/redshift/latest/dg/t_loading-tables-from-s3.html

分享给朋友:
您可能感兴趣的文章:
随机阅读: