func RequestNodeCordon()

in nvidia-efa-ami_base/support/main.go [115:181]


func RequestNodeCordon(nvidialogs []string) (string, error) {
	mySession := session.Must(session.NewSession())

	/**
	 * We can get credentials 3 ways:
	 * https://github.com/aws/aws-sdk-go#configuring-credentials
	 * Initial credentials loaded from SDK's default credential chain. Such as
     * the environment, shared credentials (~/.aws/credentials), or EC2 Instance
     * Role. These credentials will be used to to make the STS Assume Role API.
	 */

	// Support's API is only available in us-east-1
	// See: https://docs.aws.amazon.com/general/latest/gr/awssupport.html
	client := support.New(mySession, aws.NewConfig().WithRegion("us-east-1"))

	atsId, err := uploadLogs(client, nvidialogs)
	if err != nil {
		return "", err
	}

	emdClient := ec2metadata.New(mySession)
	if !emdClient.Available() {
		return "", errors.New("Cannot connect to ec2 metadata service")
	}

	iid, err := emdClient.GetInstanceIdentityDocument()
	if err != nil {
		return "", err
	}

	body, err := genCaseBody(iid)
	if err != nil {
		return "", err
	}
	fmt.Println(body)

	// Populate case fields
	supportCase := new(support.CreateCaseInput)
	supportCase.SetCcEmailAddresses(CC_EMAILS)
	supportCase.SetSubject(CASE_SUBJECT)
	supportCase.SetCommunicationBody(body)
	supportCase.SetIssueType("technical")
	supportCase.SetLanguage("en")

	// A list of support case service codes & category codes can be found using the CLI:
	// $ aws support describe-services --region=us-east-1
	supportCase.SetServiceCode("amazon-elastic-compute-cloud-linux")
	supportCase.SetCategoryCode("instance-issue")

	// A list of suport case severity levels and associated code can be found using the CLI:
	// $ aws support describe-severity-levels
	// critical = 15 minute target (SLO) for first response by AWS Enterprise Support
	// urgent = 1 hour target (SLO) for first response by AWS Enterprise Support
	supportCase.SetSeverityCode("critical")
	supportCase.SetAttachmentSetId(atsId)

	if err := supportCase.Validate(); err != nil {
		return "", err
	}

	res, err := client.CreateCase(supportCase)
	if err != nil {
		return "", err
	}
	return *res.CaseId, nil

}