You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

AWS Glue Spark脚本连接Redshift Serverless失败求助

解决AWS Glue Spark脚本连接Redshift Serverless失败的问题

针对你遇到的Spark脚本无法连接Redshift Serverless但可视化ETL正常的问题,可按以下步骤排查修复:

1. 移除冲突的连接参数

你在脚本中同时设置了useConnectionProperties": "true"和aws-iam-user,这会导致认证逻辑冲突。当启用useConnectionProperties时,Glue会直接复用你在Glue Catalog中配置的Redshift连接的认证信息(包括IAM角色),无需额外指定aws-iam-user。

修正后的脚本:

target_Redshift = glueContext.write_dynamic_frame.from_options(
    frame=changeSchema_Transformation,
    connection_type="redshift",
    connection_options={
        "redshiftTmpDir": f"s3://{redshiftTmpDir_s3}/temporary/",
        "useConnectionProperties": "true",
        "dbtable": targer_redshift_dbtable,
        "connectionName": redshift_connection_name,
        # 可选:如果需要预执行SQL,取消注释并完善语句
        # "preactions": "CREATE TABLE IF NOT EXISTS your_schema.your_table (...)",
    },
    transformation_ctx="target_Redshift",
)

2. 验证网络访问配置

  • 确认Redshift Serverless工作组的网络设置允许Glue作业访问:
    • 如果Glue作业运行在VPC内,检查Redshift Serverless工作组的安全组入站规则是否允许Glue作业所在VPC的安全组/IP段访问5439端口(Redshift默认端口)
    • 如果Glue作业是公网访问模式,确认Redshift Serverless工作组已启用公网访问,且安全组允许公网IP访问
  • 检查Glue作业所在VPC的出站规则,确保允许访问Redshift Serverless的端点和S3临时目录

3. 确认IAM权限配置

  • Glue作业的执行角色需具备:
    • 对redshiftTmpDir指定的S3路径的读写权限(s3:GetObject、s3:PutObject、s3:ListBucket)
    • 读取Glue Catalog中Redshift连接的权限(glue:GetConnection)
    • 访问Redshift Serverless的权限,包括获取临时凭证的权限(redshift-serverless:GetCredentials)
  • Redshift Serverless的IAM角色需具备访问S3临时目录的权限,以便从该目录加载数据

4. 检查临时S3目录的可用性

确保redshiftTmpDir对应的S3路径已存在,且Glue角色和Redshift Serverless角色都有该路径的访问权限——Redshift需要从这个临时目录读取转换后的数据,权限不足会导致连接或加载失败


内容的提问来源于stack exchange,提问作者pc_fuel

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.10 15:25:25