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

AWS EMR创建集群时S3配置文件的正确路径及参数报错解决

解决AWS EMR create-cluster中--configurations参数的S3路径问题

核心问题原因

aws emr create-cluster的--configurations参数不支持直接传入HTTPS格式的S3 URL,它仅接受两种输入形式:

  • 本地文件路径(需带file://前缀)
  • 直接嵌入的JSON字符串

即使S3存储桶设为公开,CLI也不会通过HTTPS请求读取S3上的JSON文件,因此会抛出"invalid json argument"错误。

正确的解决方案

方案1:先下载S3文件到本地再使用

先将S3上的配置文件下载到本地,再用本地路径传入参数:

# 下载S3配置文件到本地
aws s3 cp s3://<your-bucket-name>/<path-to-config.json> ./emr-config.json

# 执行创建集群命令
aws emr create-cluster \
--name task5-emr \
--use-default-roles \
--configurations file://./emr-config.json \
--release-label emr-6.3.1 \
--instance-count 2 \
--instance-type m3.xlarge \
--applications Name=Spark Name=Hadoop \
--ec2-attributes KeyName=<my key>

方案2:使用进程替换直接读取S3内容(适用于bash/zsh环境)

通过进程替换直接将S3文件内容作为本地文件传入,无需手动下载:

aws emr create-cluster \
--name task5-emr \
--use-default-roles \
--configurations file://<(aws s3 cp s3://<your-bucket-name>/<path-to-config.json> -) \
--release-label emr-6.3.1 \
--instance-count 2 \
--instance-type m3.xlarge \
--applications Name=Spark Name=Hadoop \
--ec2-attributes KeyName=<my key>

方案3:直接嵌入JSON字符串(适合短配置)

如果配置内容不长,可以直接将JSON字符串嵌入命令中:

aws emr create-cluster \
--name task5-emr \
--use-default-roles \
--configurations '[
  {
    "Classification": "yarn-site",
    "Properties": {
      "yarn.resourcemanager.scheduler.class": "org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.FairScheduler"
    },
    "Configurations": []
  },
  {
    "Classification": "spark-defaults",
    "Properties": {
      "spark.scheduler.mode": "FAIR",
      "spark.scheduler.allocation.file": "/etc/hadoop/conf/fairscheduler.xml"
    },
    "Configurations": []
  }
]' \
--release-label emr-6.3.1 \
--instance-count 2 \
--instance-type m3.xlarge \
--applications Name=Spark Name=Hadoop \
--ec2-attributes KeyName=<my key>

注意事项

  • 方案2中的进程替换仅在bash或zsh环境下有效,其他shell可能不支持
  • 确保执行命令的IAM角色或用户拥有读取目标S3文件的权限(即使桶公开,也需确认权限配置无冲突)

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.22 20:54:29