DeleteUser.go - AWS Code Sample

DeleteUser.go

// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: MIT-0 package main import ( "flag" "fmt" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/iam" "github.com/aws/aws-sdk-go/service/iam/iamiface" ) // RemoveUser deletes an IAM user // Inputs: // sess is the current session, which provides configuration for the SDK's service clients // userName is the name of the user // Output: // If success, nil // Otherwise, an error from the call to DeleteUser func RemoveUser(svc iamiface.IAMAPI, userName *string) error { _, err := svc.DeleteUser(&iam.DeleteUserInput{ UserName: userName, }) return err } func main() { userName := flag.String("u", "", "The name of the user") flag.Parse() if *userName == "" { fmt.Println("You must supply a user name (-u USERNAME)") return } sess := session.Must(session.NewSessionWithOptions(session.Options{ SharedConfigState: session.SharedConfigEnable, })) svc := iam.New(sess) err := RemoveUser(svc, userName) if err != nil { fmt.Println("Got an error deleting user " + *userName) } fmt.Println("Deleted user " + *userName) }