我正在尝试通过SQL脚本使用Redshift Copy Command,我需要通过shell变量传递Access密钥和Secret密钥。但是由于Redshift Copy Command的格式,我无法传递shell Variables。
COPY ${REDSHIFT_SCHEMA_NAME}.${REDSHIFT_TABLE_NAME} FROM ${S3_SOURCE} credentials 'aws_access_key_id=${AWS_ACCESS_KEY_ID};aws_secret_access_key=${AWS_SECRET_ACCESS_KEY}' delimiter '${DELIMITER}' COMPUPDATE OFF STATUPDATE OFF;
我面临的问题是AWS_SECRET_ACCESS_KEY和AWS_ACCESS_KEY_ID没有解决,因为它们都在' '单引号。
使用命令
COPY ${REDSHIFT_SCHEMA_NAME}.${REDSHIFT_TABLE_NAME_BACKLOG} FROM ${S3_SOURCE} credentials aws_access_key_id='${AWS_ACCESS_KEY_ID}';aws_secret_access_key='${AWS_SECRET_ACCESS_KEY}' delimiter '${DELIMITER}' COMPUPDATE OFF STATUPDATE OFF;
复制命令的格式变得不正确。 还有其他解决办法吗?
答案 0 :(得分:0)
亚马逊提供了非常好的文档。 我通过谷歌搜索找到了你正在寻找的东西:'Redshift shell copy'
以下是包含工作shell脚本的文章:
https://aws.amazon.com/articles/1143507459230804
我用过它,它对我有用:
#!/bin/bash
set -eu
AWS_ACCESS_KEY_ID='my_access_key'
AWS_SECRET_ACCESS_KEY='my_secret_access_key'
REDSHIFT_SCHEMA_NAME='redshift_schema_name'
REDSHIFT_TABLE_NAME_BACKLOG='redshift_table_name_backlog'
S3_SOURCE='s3_source'
DELIMITER='delimiter'
cmd="COPY ${REDSHIFT_SCHEMA_NAME}.${REDSHIFT_TABLE_NAME_BACKLOG} FROM ${S3_SOURCE} credentials aws_access_key_id='${AWS_ACCESS_KEY_ID}';aws_secret_access_key='${AWS_SECRET_ACCESS_KEY}' delimiter '${DELIMITER}' COMPUPDATE OFF STATUPDATE OFF;"
echo $cmd