sultanGULLU
sultanGULLU

Reputation: 21

EMR cluster is not terminating while deleting the associated cloudformation stack using lambda function

Resources:
  LFTULJ:
    Type: 'AWS::Lambda::Function'
    Properties:
      Runtime: python3.6
      Code:
        ZipFile: |
          import boto3
          import os
          import json

          stack_name = os.environ['stackName']

          def delete_cfn(stack_name):
              try:
                  cfn = boto3.resource('cloudformation')
                  stack = cfn.Stack(stack_name)
                  stack.delete()
                  return "SUCCESS"
              except:
                  return "ERROR"

          def handler(event,context):
              print("Received event:")
              print(json.dumps(event))
              return delete_cfn(stack_name)

      Handler: index.handler
      Environment: 
        Variables: 
          stackName: shubham
      Role: 'arn:aws:iam::261598744157:role/terminate'
      Timeout: '60'
    Metadata:
      'AWS::CloudFormation::Designer':
        id: 20d06512-220b-4ef6-b56a-f65d2a0c49d4

I am deleting the stack using lambda function. Everything is getting deleted but EMR cluster is not terminating. The error shown is Cluster id 'j-AQ1M94XKWDDJP' is not valid. (Service: AmazonElasticMapReduce; Status Code: 400; Error Code: InvalidRequestException; Request ID: 0283892f-c5aa-440d-968a-8cfb4585fe23) while a cluster with that ID exists.

Upvotes: 0

Views: 419

Answers (2)

Saptarsi Basu
Saptarsi Basu

Reputation: 23

I set VisibleToAllUsers property value True but still facing the issue.

Throwing error message: Cluster id 'j-2NTFNCJLFN87I' is not valid. (Service: AmazonElasticMapReduce; Status Code: 400; Error Code: InvalidRequestException; Request ID: 6b7e5c5b-fffa-457f-8897-9417846452e0; Proxy: null)

Upvotes: 0

sultanGULLU
sultanGULLU

Reputation: 21

i got the answer to problem. There is one property associated with EMR cluster VisibleToAllUsers. When we spin our EMR cluster using CLoudformation script it's default value is set which is false. So that's why EMR id was not valid. SO the solution for it is to make the VisibleToAllUsers property to true than other IAM can also view the EMR cluster and than the script and lambda function works correctly.

Upvotes: 1

Related Questions