bruvio
bruvio

Reputation: 1093

adding ec2 key pair to EMR cluster using cloudformation

I am trying to write a template to create a EMR cluster using cloudformation.

So far I came up with this

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

I create the default role somewhere else (not using cloudformation at the moment)

I would like to understand how to add the EC2 keypair so I can ssh into the nodes.

any help?

using cli seems more straitforward

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

Upvotes: 0

Views: 967

Answers (1)

Marcin
Marcin

Reputation: 238249

There is Ec2KeyName parameter:

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

Upvotes: 1

Related Questions