Automate AWS Enterprise Support Activation for Member Accounts
Tags: aws, stepfunctions, awsorganizations, awssupport
Published: 2023-03-13 07:16:45

## Why do we need automation?

Member accounts added to AWS Organizations after subscribing to Enterprise Support are not enrolled in Enterprise Support.

To register a new member account with Enterprise Support, you must open a support case in the management account.

## Example

This example is a simple workflow that executes case creation, close confirmation, and notification with AWS Step Functions.

### Input

You can use Amazon EventBrige to trigger the CreateAccount event in AWS Organizations or the CreateManagedAccount event in AWS Control Tower to launch the state machine.

Therefore, the input for the state machine is a single account as follows.

```json
{
  "AccountId": "<Account ID>"
}
```

### State machine definition

The process flow is as follows. Creating cases and checking status uses AWS SDK service integrations.

* In the CeateCase state, create a support case with the account ID received from the state machine startup input as the activation target
    
* Execute the DescribeCases state based on the Case ID returned as the result of the CreateCase state task.
    
    * DescribeCases API requires passing a list of case IDs, so use the built-in function [States.Array](https://docs.aws.amazon.com/ja_jp/step-functions/latest/dg/amazon-states-language-intrinsic-functions.html#asl-intrsc-func-arrays).
        
    * Since the task result is also a list, specify `$.Cases[0]` in OutputPath.
        
* In the Choice state, check the status of support cases from the DescirbeCases output
    
    * If `resolved`, proceed to SNS Pulibsh state.
        
    * Otherwise, wait for a specified time in the Wait state and execute DescribeCases again.
        
* In the SNS Publish state, publish a message to the specified SNS Topic
    

```json
{
  "Comment": "A description of your state machine",
  "StartAt": "CreateCase",
  "States": {
    "CreateCase": {
      "Type": "Task",
      "Parameters": {
        "Subject": "Enterprise Activation Request for Linked account",
        "ServiceCode": "customer-account",
        "SeverityCode": "low",
        "CategoryCode": "other-account-issues",
        "CommunicationBody.$": "States.Format('Please enable Enterprise support for following account ID:\n{}\n', $.AccountId)",
        "Language": "en",
        "IssueType": "customer-service"
      },
      "Resource": "arn:aws:states:::aws-sdk:support:createCase",
      "Next": "DescribeCases"
    },
    "DescribeCases": {
      "Type": "Task",
      "Parameters": {
        "CaseIdList.$": "States.Array($.CaseId)",
        "IncludeResolvedCases": true
      },
      "Resource": "arn:aws:states:::aws-sdk:support:describeCases",
      "Next": "Choice",
      "OutputPath": "$.Cases[0]"
    },
    "Choice": {
      "Type": "Choice",
      "Choices": [
        {
          "Variable": "$.Status",
          "StringEquals": "resolved",
          "Next": "SNS Publish"
        }
      ],
      "Default": "Wait"
    },
    "SNS Publish": {
      "Type": "Task",
      "Resource": "arn:aws:states:::sns:publish",
      "Parameters": {
        "Message.$": "$",
        "TopicArn": "arn:aws:sns:us-east-1:123456789012:your-sns-topic"
      },
      "End": true
    },
    "Wait": {
      "Type": "Wait",
      "Seconds": 30,
      "Next": "DescribeCases"
    }
  }
}
```

On Workflow Studio, it is displayed as follows.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u0qoto89am19ax0d7cpa.png)

### Execution example

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vm90qcmad16af2koyi4d.png)


I hope this will be of help to someone else.