使用 cloudformation 将 ec2 密钥对添加到 EMR 集群

adding ec2 key pair to EMR cluster using cloudformation

我正在尝试编写一个模板来使用 cloudformation 创建 EMR 集群。

到目前为止我想到了这个

AWSTemplateFormatVersion: 2010-09-09

Parameters:
  SubnetId:
    Type: "String"
    Default: "subnet-0caca76de8cc43e70"
  ClusterName:
    Type: "String"
    Default: "Example_Three_Node_Cluster"
  EmrRelease:
    Type: "String"
    Default: "emr-6.2.0"
    AllowedValues:
    - "emr-6.2.0"
    - "emr-5.32.0"
  ClusterInstanceType:
    Type: "String"
    Default: "m5.xlarge"
    AllowedValues:
    - "m5.xlarge"
    - "m5.2xlarge"

Resources:
  EmrCluster:
    Type: AWS::EMR::Cluster
    Properties:
      Applications:
      - Name: Spark
      - Name: Livy
      - Name: JupyterEnterpriseGateway
      - Name: Hive
      EbsRootVolumeSize: '10'
      Name: !Ref ClusterName
      JobFlowRole: EMR_EC2_DefaultRole
      ServiceRole: EMR_DefaultRole
      ReleaseLabel: !Ref EmrRelease
      VisibleToAllUsers: true
      LogUri: 
        Fn::Sub: 's3://aws-logs-${AWS::AccountId}-${AWS::Region}/elasticmapreduce/'
      Instances:
        TerminationProtected: false
        Ec2SubnetId: !Ref SubnetId
        MasterInstanceGroup:
          InstanceCount: 1
          InstanceType: !Ref ClusterInstanceType
        CoreInstanceGroup:
          InstanceCount: 2
          InstanceType: !Ref ClusterInstanceType
          Market: ON_DEMAND
          Name: Core

Outputs:
  ClusterId:
    Value:
      Ref: EmrCluster
    Description: The ID of the EMR Cluster

我在别处创建默认角色(目前不使用 cloudformation)

我想了解如何添加 EC2 密钥对以便我可以通过 ssh 进入节点。

有什么帮助吗?

使用 cli 似乎更直接

aws emr create-cluster \
--name "MyCluster" \
--release-label emr-5.33.1 \
--applications Name=Spark \
--ec2-attributes KeyName=MyKey \
--instance-type m5.xlarge \
--instance-count 3 \
--use-default-roles

Ec2KeyName个参数:

The name of the EC2 key pair that can be used to connect to the master node using SSH as the user called "hadoop."