Airflow/Amazon EMR: The VPC/subnet configuration was invalid: Subnet is required : The specified instance type m5.xlarge can only be used in a VPC

问题描述

我想在 Amazon EMR 上创建一个通过 Airflow 触发的 emr 集群。 emr 集群显示在 Amazon EMR 的 UI 中,但有一条错误消息: “VPC/子网配置无效:需要子网:指定的实例类型m5.xlarge只能在VPC中使用”

以下是 Airflow 脚本中使用的此任务的 json 格式的代码片段和配置详细信息。

我的问题是如何将有关 VPC 和子网的信息(id 代码)合并到 json 中(如果这可能的话)?没有明确的例子。

提示:已经创建了一个网络和一个 EC2 子网

JOB_FLOW_OVERRIDES = {
    "Name": "sentiment_analysis","ReleaseLabel": "emr-5.33.0","Applications": [{"Name": "Hadoop"},{"Name": "Spark"}],# We want our EMR cluster to have HDFS and Spark
    "Configurations": [
        {
            "Classification": "spark-env","Configurations": [
                {
                    "Classification": "export","Properties": {"PYSPARK_PYTHON": "/usr/bin/python3"},# by default EMR uses py2,change it to py3
                }
            ],}
    ],"Instances": {
        "InstanceGroups": [
            {
                "Name": "Master node","Market": "SPOT","InstanceRole": "MASTER","InstanceType": "m5.xlarge","InstanceCount": 1,},{
                "Name": "Core - 2",# Spot instances are a "use as available" instances
                "InstanceRole": "CORE","InstanceCount": 2,],"KeepJobFlowAliveWhenNoSteps": True,"TerminationProtected": False,# this lets us programmatically terminate the cluster
    },"JobFlowRole": "EMR_EC2_DefaultRole","ServiceRole": "EMR_DefaultRole",}

create_emr_cluster = EmrCreateJobFlowOperator(
    task_id="create_emr_cluster",job_flow_overrides=JOB_FLOW_OVERRIDES,aws_conn_id="aws_default",emr_conn_id="emr_default",dag=dag,)

解决方法

EmrCreateJobFlowOperator 从 emr.py 调用 create_job_flow,它与来自 boto3 emr client 的相同 api 匹配。

因此,您可以将带有子网 ID 的项目 "Ec2SubnetId" 作为值放入 "Instances" 字典中。

这适用于我在 Apache Airflow 2.0.2 上

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...