go/iam/README.md
These examples demonstrate how to perform several IAM operations.
You must have an AWS account, and have your default credentials and AWS Region configured as described in Configuring the AWS SDK for Go in the AWS SDK for Go Developer Guide.
This example retrieves when an access key was last used, including in which service and AWS Region.
go run AccessKeyLastUsed.go -k KEY-ID
The unit test mocks the IAM service client an AccessKeyLastUsed function.
This example attaches an Amazon DynamoDB full-access policy to an IAM role.
go run AttachUserPolicy.go -r ROLE
The unit test mocks the service client and the AttachRolePolicy function.
This example creates a new access key ID and secret key for a user.
go run CreateAccessKey.go -u USER
The unit test mocks the IAM service client and CreateAccessKey function.
This example creates an alias for your IAM account.
go run CreateAccountAlias.go -a ALIAS
The unit test mocks the service client and the CreateAccountAlias function.
This example creates a new policy.
go run CreatePolicy.go -n POLICY
The unit test mocks the service client and the CreatePolicy function.
This example creates a new IAM user.
go run CreateUser.go -u USERNAME
The unit test mocks the service client and the CreateUser function.
This example deletes an IAM access key.
go run DeleteAccessKey.go -k KEY-ID -u USER-NAME
The unit test mocks the IAM service client and the DeleteAccessKey function.
This example removes an alias for an IAM account.
go run DeleteAccountAlias.go -a ALIAS
The unit test mocks the IAM service client and the DeleteAccountAlias function.
This example deletes an IAM server certificate.
go run DeleteServerCert.go -c CERT-NAME
The unit test mocks the IAM service client and the DeleteServerCertificate function.
This example deletes an IAM user.
go run DeleteUser.go -u USERNAME
The unit test mocks the service client and the DeleteUser function.
This example detaches an Amazon DynamoDB full-access policy from an IAM role.
go run DetachUserPolicy.go -r ROLE
The unit test mocks the service client and the DetachRolePolicy function.
This example retrieves the description for a policy.
go run GetPolicy.go -a POLICY-ARN
The unit test mocks the IAM service client and the GetPolicy function.
This example gets the bodies of a user's public SSH keys.
go run GetPublicKeys -u USER-NAME
The unit test mocks the IAM service client and the ListSSHPublicKeys function.
This example retrieves information about an IAM server certificate.
go run GetServerCert.go -c CERT-NAME
The unit test mocks the IAM service client and the GetServerCertificate function.
This example lists the accesss keys for a specific user.
go run ListAccessKeys -u USER
The unit test mocks the IAM service client and the ListAccessKeys function.
This example lists the aliases for your account.
go run ListAccountAliases -m MAX-ITEMS
The unit test mocks the service client and the ListAccountAliases function.
This example lists the number of users and users who have administrative rights.
go run ListAdmins.go
This example lists the metadata about your server certificates.
go run ListServerCerts.go
The unit test mocks the IAM service client and the ListServerCertificates function.
This example lists your IAM users.
go run ListUsers.go [-m MAX-USERS]
The unit test accepts a similar value in config.json.
This example activates an access key.
go run UpdateAccessKey.go -k KEY-ID -u USER-NAME
The unit test mocks the IAM service client and the UpdateAccessKey function.
This example renames an IAM server certificate.
go run UpdateServerCert.go -c CERT-NAME -n NEW-NAME
The unit test mocks the IAM service client and the UpdateServerCertificate function.
This example changes the name of an existing IAM user.
go run UpdateUser.go -u USERNAME -n NEW-NAME
The unit test mocks the service client and the UpdateUser function.
Unit tests should delete any resources they create. However, they might result in charges to your AWS account.
To run a unit test, enter the following:
go test
You should see something like the following, where PATH is the path to the folder containing the Go files.
PASS
ok PATH 6.593s
If you want to see any log messages, enter the following:
go test -test.v
You should see some additional log messages. The last two lines should be similar to the previous output shown.
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. SPDX-License-Identifier: Apache-2.0