AWS SDK for Go (PILOT)
API Reference

PREVIEW DOCUMENTATION - This is a preview of a new format for the AWS SDK for Go API Reference documentation. For the current AWS SDK for Go API Reference, see https://docs.aws.amazon.com/sdk-for-go/api/.

We welcome your feedback on this new version of the documentation. Send your comments to aws-sdkdocs-feedback@amazon.com.

KMS

import "github.com/aws/aws-sdk-go/service/kms"

type KMS struct { *client.Client }

KMS provides the API operation methods for making requests to AWS Key Management Service. See this package's package overview docs for details on the service.

KMS methods are safe to use concurrently. It is not safe to modify mutate any of the struct's properties though.

Client

Type: *client.Client

Method

CancelKeyDeletion

func (c *KMS) CancelKeyDeletion(input *CancelKeyDeletionInput) (*CancelKeyDeletionOutput, error)

CancelKeyDeletion API operation for AWS Key Management Service.

Cancels the deletion of a customer master key (CMK). When this operation is successful, the CMK is set to the Disabled state. To enable a CMK, use EnableKey. You cannot perform this operation on a CMK in a different AWS account.

For more information about scheduling and canceling deletion of a CMK, see Deleting Customer Master Keys (https://docs.aws.amazon.com/kms/latest/developerguide/deleting-keys.html) in the AWS Key Management Service Developer Guide.

The result of this operation varies with the key state of the CMK. For details, see How Key State Affects Use of a Customer Master Key (https://docs.aws.amazon.com/kms/latest/developerguide/key-state.html) in the AWS Key Management Service Developer Guide.

Returns awserr.Error for service API and SDK errors. Use runtime type assertions with awserr.Error's Code and Message methods to get detailed information about the error.

See the AWS API reference guide for AWS Key Management Service's API operation CancelKeyDeletion for usage and error information.

Returned Error Codes:

  • ErrCodeNotFoundException "NotFoundException" The request was rejected because the specified entity or resource could not be found.

  • ErrCodeInvalidArnException "InvalidArnException" The request was rejected because a specified ARN was not valid.

  • ErrCodeDependencyTimeoutException "DependencyTimeoutException" The system timed out while trying to fulfill the request. The request can be retried.

  • ErrCodeInternalException "KMSInternalException" The request was rejected because an internal exception occurred. The request can be retried.

  • ErrCodeInvalidStateException "KMSInvalidStateException" The request was rejected because the state of the specified resource is not valid for this request.

For more information about how key state affects the use of a CMK, see How Key State Affects Use of a Customer Master Key (http://docs.aws.amazon.com/kms/latest/developerguide/key-state.html) in the AWS Key Management Service Developer Guide.

See also, https://docs.aws.amazon.com/goto/WebAPI/kms-2014-11-01/CancelKeyDeletion

Example

KMS CancelKeyDeletion shared00

To cancel deletion of a customer master key (CMK)

The following example cancels deletion of the specified CMK.

{ svc := kms.New(session.New()) input := &kms.CancelKeyDeletionInput{ KeyId: aws.String("1234abcd-12ab-34cd-56ef-1234567890ab"), } result, err := svc.CancelKeyDeletion(input) if err != nil { if aerr, ok := err.(awserr.Error); ok { switch aerr.Code() { case kms.ErrCodeNotFoundException: fmt.Println(kms.ErrCodeNotFoundException, aerr.Error()) case kms.ErrCodeInvalidArnException: fmt.Println(kms.ErrCodeInvalidArnException, aerr.Error()) case kms.ErrCodeDependencyTimeoutException: fmt.Println(kms.ErrCodeDependencyTimeoutException, aerr.Error()) case kms.ErrCodeInternalException: fmt.Println(kms.ErrCodeInternalException, aerr.Error()) case kms.ErrCodeInvalidStateException: fmt.Println(kms.ErrCodeInvalidStateException, aerr.Error()) default: fmt.Println(aerr.Error()) } } else { fmt.Println(err.Error()) } return } fmt.Println(result) }

CancelKeyDeletionRequest

func (c *KMS) CancelKeyDeletionRequest(input *CancelKeyDeletionInput) (req *request.Request, output *CancelKeyDeletionOutput)

CancelKeyDeletionRequest generates a "aws/request.Request" representing the client's request for the CancelKeyDeletion operation. The "output" return value will be populated with the request's response once the request completes successfully.

Use "Send" method on the returned Request to send the API call to the service. the "output" return value is not valid until after Send returns without error.

See CancelKeyDeletion for more information on using the CancelKeyDeletion API call, and error handling.

This method is useful when you want to inject custom logic or configuration into the SDK's request lifecycle. Such as custom headers, or retry logic.

// Example sending a request using the CancelKeyDeletionRequest method. req, resp := client.CancelKeyDeletionRequest(params) err := req.Send() if err == nil { // resp is now filled fmt.Println(resp) }

See also, https://docs.aws.amazon.com/goto/WebAPI/kms-2014-11-01/CancelKeyDeletion

CancelKeyDeletionWithContext

func (c *KMS) CancelKeyDeletionWithContext(ctx aws.Context, input *CancelKeyDeletionInput, opts ...request.Option) (*CancelKeyDeletionOutput, error)

CancelKeyDeletionWithContext is the same as CancelKeyDeletion with the addition of the ability to pass a context and additional request options.

See CancelKeyDeletion for details on how to use this API operation.

The context must be non-nil and will be used for request cancellation. If the context is nil a panic will occur. In the future the SDK may create sub-contexts for http.Requests. See https://golang.org/pkg/context/ for more information on using Contexts.

See Also

For more information about using this API, see AWS API Documentation.

ConnectCustomKeyStore

func (c *KMS) ConnectCustomKeyStore(input *ConnectCustomKeyStoreInput) (*ConnectCustomKeyStoreOutput, error)

ConnectCustomKeyStore API operation for AWS Key Management Service.

Connects or reconnects a custom key store (https://docs.aws.amazon.com/kms/latest/developerguide/key-store-overview.html) to its associated AWS CloudHSM cluster.

The custom key store must be connected before you can create customer master keys (CMKs) in the key store or use the CMKs it contains. You can disconnect and reconnect a custom key store at any time.

To connect a custom key store, its associated AWS CloudHSM cluster must have at least one active HSM. To get the number of active HSMs in a cluster, use the DescribeClusters (https://docs.aws.amazon.com/cloudhsm/latest/APIReference/API_DescribeClusters) operation. To add HSMs to the cluster, use the CreateHsm (https://docs.aws.amazon.com/cloudhsm/latest/APIReference/API_CreateHsm) operation.

The connection process can take an extended amount of time to complete; up to 20 minutes. This operation starts the connection process, but it does not wait for it to complete. When it succeeds, this operation quickly returns an HTTP 200 response and a JSON object with no properties. However, this response does not indicate that the custom key store is connected. To get the connection state of the custom key store, use the DescribeCustomKeyStores operation.

During the connection process, AWS KMS finds the AWS CloudHSM cluster that is associated with the custom key store, creates the connection infrastructure, connects to the cluster, logs into the AWS CloudHSM client as the kmsuser (https://docs.aws.amazon.com/kms/latest/developerguide/key-store-concepts.html#concept-kmsuser) crypto user (CU), and rotates its password.

The ConnectCustomKeyStore operation might fail for various reasons. To find the reason, use the DescribeCustomKeyStores operation and see the ConnectionErrorCode in the response. For help interpreting the ConnectionErrorCode, see CustomKeyStoresListEntry.

To fix the failure, use the DisconnectCustomKeyStore operation to disconnect the custom key store, correct the error, use the UpdateCustomKeyStore operation if necessary, and then use ConnectCustomKeyStore again.

If you are having trouble connecting or disconnecting a custom key store, see Troubleshooting a Custom Key Store (https://docs.aws.amazon.com/kms/latest/developerguide/fix-keystore.html) in the AWS Key Management Service Developer Guide.

Returns awserr.Error for service API and SDK errors. Use runtime type assertions with awserr.Error's Code and Message methods to get detailed information about the error.

See the AWS API reference guide for AWS Key Management Service's API operation ConnectCustomKeyStore for usage and error information.

Returned Error Codes:

  • ErrCodeCloudHsmClusterNotActiveException "CloudHsmClusterNotActiveException" The request was rejected because the AWS CloudHSM cluster that is associated with the custom key store is not active. Initialize and activate the cluster and try the command again. For detailed instructions, see Getting Started

(http://docs.aws.amazon.com/cloudhsm/latest/userguide/getting-started.html) in the AWS CloudHSM User Guide.
  • ErrCodeCustomKeyStoreInvalidStateException "CustomKeyStoreInvalidStateException" The request was rejected because of the ConnectionState of the custom key store. To get the ConnectionState of a custom key store, use the DescribeCustomKeyStores operation.

This exception is thrown under the following conditions:
  • You requested the CreateKey or GenerateRandom operation in a custom key store that is not connected. These operations are valid only when the custom key store ConnectionState is CONNECTED.

  • You requested the UpdateCustomKeyStore or DeleteCustomKeyStore operation on a custom key store that is not disconnected. This operation is valid only when the custom key store ConnectionState is DISCONNECTED.

  • You requested the ConnectCustomKeyStore operation on a custom key store with a ConnectionState of DISCONNECTING or FAILED. This operation is valid for all other ConnectionState values.

  • ErrCodeCustomKeyStoreNotFoundException "CustomKeyStoreNotFoundException" The request was rejected because AWS KMS cannot find a custom key store with the specified key store name or ID.

  • ErrCodeInternalException "KMSInternalException" The request was rejected because an internal exception occurred. The request can be retried.

  • ErrCodeCloudHsmClusterInvalidConfigurationException "CloudHsmClusterInvalidConfigurationException" The request was rejected because the associated AWS CloudHSM cluster did not meet the configuration requirements for a custom key store. The cluster must be configured with private subnets in at least two different Availability Zones in the Region. Also, it must contain at least as many HSMs as the operation requires.

For the CreateCustomKeyStore, UpdateCustomKeyStore, and CreateKey operations, the AWS CloudHSM cluster must have at least two active HSMs, each in a different Availability Zone. For the ConnectCustomKeyStore operation, the AWS CloudHSM must contain at least one active HSM. For information about creating a private subnet for a AWS CloudHSM cluster, see Create a Private Subnet (http://docs.aws.amazon.com/cloudhsm/latest/userguide/create-subnets.html) in the AWS CloudHSM User Guide. To add HSMs, use the AWS CloudHSM CreateHsm (http://docs.aws.amazon.com/cloudhsm/latest/APIReference/API_CreateHsm.html) operation.

See also, https://docs.aws.amazon.com/goto/WebAPI/kms-2014-11-01/ConnectCustomKeyStore

ConnectCustomKeyStoreRequest

func (c *KMS) ConnectCustomKeyStoreRequest(input *ConnectCustomKeyStoreInput) (req *request.Request, output *ConnectCustomKeyStoreOutput)

ConnectCustomKeyStoreRequest generates a "aws/request.Request" representing the client's request for the ConnectCustomKeyStore operation. The "output" return value will be populated with the request's response once the request completes successfully.

Use "Send" method on the returned Request to send the API call to the service. the "output" return value is not valid until after Send returns without error.

See ConnectCustomKeyStore for more information on using the ConnectCustomKeyStore API call, and error handling.

This method is useful when you want to inject custom logic or configuration into the SDK's request lifecycle. Such as custom headers, or retry logic.

// Example sending a request using the ConnectCustomKeyStoreRequest method. req, resp := client.ConnectCustomKeyStoreRequest(params) err := req.Send() if err == nil { // resp is now filled fmt.Println(resp) }

See also, https://docs.aws.amazon.com/goto/WebAPI/kms-2014-11-01/ConnectCustomKeyStore

ConnectCustomKeyStoreWithContext

func (c *KMS) ConnectCustomKeyStoreWithContext(ctx aws.Context, input *ConnectCustomKeyStoreInput, opts ...request.Option) (*ConnectCustomKeyStoreOutput, error)

ConnectCustomKeyStoreWithContext is the same as ConnectCustomKeyStore with the addition of the ability to pass a context and additional request options.

See ConnectCustomKeyStore for details on how to use this API operation.

The context must be non-nil and will be used for request cancellation. If the context is nil a panic will occur. In the future the SDK may create sub-contexts for http.Requests. See https://golang.org/pkg/context/ for more information on using Contexts.

See Also

For more information about using this API, see AWS API Documentation.

CreateAlias

func (c *KMS) CreateAlias(input *CreateAliasInput) (*CreateAliasOutput, error)

CreateAlias API operation for AWS Key Management Service.

Creates a display name for a customer master key (CMK). You can use an alias to identify a CMK in selected operations, such as Encrypt and GenerateDataKey.

Each CMK can have multiple aliases, but each alias points to only one CMK. The alias name must be unique in the AWS account and region. To simplify code that runs in multiple regions, use the same alias name, but point it to a different CMK in each region.

Because an alias is not a property of a CMK, you can delete and change the aliases of a CMK without affecting the CMK. Also, aliases do not appear in the response from the DescribeKey operation. To get the aliases of all CMKs, use the ListAliases operation.

An alias must start with the word alias followed by a forward slash (alias/). The alias name can contain only alphanumeric characters, forward slashes (/), underscores (_), and dashes (-). Alias names cannot begin with aws; that alias name prefix is reserved by Amazon Web Services (AWS).

The alias and the CMK it is mapped to must be in the same AWS account and the same region. You cannot perform this operation on an alias in a different AWS account.

To map an existing alias to a different CMK, call UpdateAlias.

The result of this operation varies with the key state of the CMK. For details, see How Key State Affects Use of a Customer Master Key (https://docs.aws.amazon.com/kms/latest/developerguide/key-state.html) in the AWS Key Management Service Developer Guide.

Returns awserr.Error for service API and SDK errors. Use runtime type assertions with awserr.Error's Code and Message methods to get detailed information about the error.

See the AWS API reference guide for AWS Key Management Service's API operation CreateAlias for usage and error information.

Returned Error Codes:

  • ErrCodeDependencyTimeoutException "DependencyTimeoutException" The system timed out while trying to fulfill the request. The request can be retried.

  • ErrCodeAlreadyExistsException "AlreadyExistsException" The request was rejected because it attempted to create a resource that already exists.

  • ErrCodeNotFoundException "NotFoundException" The request was rejected because the specified entity or resource could not be found.

  • ErrCodeInvalidAliasNameException "InvalidAliasNameException" The request was rejected because the specified alias name is not valid.

  • ErrCodeInternalException "KMSInternalException" The request was rejected because an internal exception occurred. The request can be retried.

  • ErrCodeInvalidStateException "KMSInvalidStateException" The request was rejected because the state of the specified resource is not valid for this request.

For more information about how key state affects the use of a CMK, see How Key State Affects Use of a Customer Master Key (http://docs.aws.amazon.com/kms/latest/developerguide/key-state.html) in the AWS Key Management Service Developer Guide.

See also, https://docs.aws.amazon.com/goto/WebAPI/kms-2014-11-01/CreateAlias

Example

KMS CreateAlias shared00

To create an alias

The following example creates an alias for the specified customer master key (CMK).

{ svc := kms.New(session.New()) input := &kms.CreateAliasInput{ AliasName: aws.String("alias/ExampleAlias"), TargetKeyId: aws.String("1234abcd-12ab-34cd-56ef-1234567890ab"), } result, err := svc.CreateAlias(input) if err != nil { if aerr, ok := err.(awserr.Error); ok { switch aerr.Code() { case kms.ErrCodeDependencyTimeoutException: fmt.Println(kms.ErrCodeDependencyTimeoutException, aerr.Error()) case kms.ErrCodeAlreadyExistsException: fmt.Println(kms.ErrCodeAlreadyExistsException, aerr.Error()) case kms.ErrCodeNotFoundException: fmt.Println(kms.ErrCodeNotFoundException, aerr.Error()) case kms.ErrCodeInvalidAliasNameException: fmt.Println(kms.ErrCodeInvalidAliasNameException, aerr.Error()) case kms.ErrCodeInternalException: fmt.Println(kms.ErrCodeInternalException, aerr.Error()) case kms.ErrCodeLimitExceededException: fmt.Println(kms.ErrCodeLimitExceededException, aerr.Error()) case kms.ErrCodeInvalidStateException: fmt.Println(kms.ErrCodeInvalidStateException, aerr.Error()) default: fmt.Println(aerr.Error()) } } else { fmt.Println(err.Error()) } return } fmt.Println(result) }

CreateAliasRequest

func (c *KMS) CreateAliasRequest(input *CreateAliasInput) (req *request.Request, output *CreateAliasOutput)

CreateAliasRequest generates a "aws/request.Request" representing the client's request for the CreateAlias operation. The "output" return value will be populated with the request's response once the request completes successfully.

Use "Send" method on the returned Request to send the API call to the service. the "output" return value is not valid until after Send returns without error.

See CreateAlias for more information on using the CreateAlias API call, and error handling.

This method is useful when you want to inject custom logic or configuration into the SDK's request lifecycle. Such as custom headers, or retry logic.

// Example sending a request using the CreateAliasRequest method. req, resp := client.CreateAliasRequest(params) err := req.Send() if err == nil { // resp is now filled fmt.Println(resp) }

See also, https://docs.aws.amazon.com/goto/WebAPI/kms-2014-11-01/CreateAlias

CreateAliasWithContext

func (c *KMS) CreateAliasWithContext(ctx aws.Context, input *CreateAliasInput, opts ...request.Option) (*CreateAliasOutput, error)

CreateAliasWithContext is the same as CreateAlias with the addition of the ability to pass a context and additional request options.

See CreateAlias for details on how to use this API operation.

The context must be non-nil and will be used for request cancellation. If the context is nil a panic will occur. In the future the SDK may create sub-contexts for http.Requests. See https://golang.org/pkg/context/ for more information on using Contexts.

See Also

For more information about using this API, see AWS API Documentation.

CreateCustomKeyStore

func (c *KMS) CreateCustomKeyStore(input *CreateCustomKeyStoreInput) (*CreateCustomKeyStoreOutput, error)

CreateCustomKeyStore API operation for AWS Key Management Service.

Creates a custom key store (https://docs.aws.amazon.com/kms/latest/developerguide/key-store-overview.html) that is associated with an AWS CloudHSM cluster (https://docs.aws.amazon.com/cloudhsm/latest/userguide/clusters.html) that you own and manage.

This operation is part of the Custom Key Store feature (https://docs.aws.amazon.com/kms/latest/developerguide/custom-key-store-overview.html) feature in AWS KMS, which combines the convenience and extensive integration of AWS KMS with the isolation and control of a single-tenant key store.

When the operation completes successfully, it returns the ID of the new custom key store. Before you can use your new custom key store, you need to use the ConnectCustomKeyStore operation to connect the new key store to its AWS CloudHSM cluster.

The CreateCustomKeyStore operation requires the following elements.

Before you create the custom key store, use the createUser (https://docs.aws.amazon.com/cloudhsm/latest/userguide/cloudhsm_mgmt_util-createUser.html)

command in cloudhsm_mgmt_util to create a crypto user (CU) named (http://docs.aws.amazon.com/kms/latest/developerguide/key-store-concepts.html#concept-kmsuser)kmsuserin specified AWS CloudHSM cluster. AWS KMS uses the kmsuser CU account to create and manage key material on your behalf. For instructions, see Create the kmsuser Crypto User (http://docs.aws.amazon.com/kms/latest/developerguide/create-keystore.html#before-keystore) in the AWS Key Management Service Developer Guide.

The AWS CloudHSM cluster that you specify must meet the following requirements.

  • The cluster must be active and be in the same AWS account and Region as the custom key store.

  • Each custom key store must be associated with a different AWS CloudHSM cluster. The cluster cannot be associated with another custom key store or have the same cluster certificate as a cluster that is associated with another custom key store. To view the cluster certificate, use the AWS CloudHSM DescribeClusters (https://docs.aws.amazon.com/cloudhsm/latest/APIReference/API_DescribeClusters.html) operation. Clusters that share a backup history have the same cluster certificate.

  • The cluster must be configured with subnets in at least two different Availability Zones in the Region. Because AWS CloudHSM is not supported in all Availability Zones, we recommend that the cluster have subnets in all Availability Zones in the Region.

  • The cluster must contain at least two active HSMs, each in a different Availability Zone.

New custom key stores are not automatically connected. After you create your custom key store, use the ConnectCustomKeyStore operation to connect the custom key store to its associated AWS CloudHSM cluster. Even if you are not going to use your custom key store immediately, you might want to connect it to verify that all settings are correct and then disconnect it until you are ready to use it.

If this operation succeeds, it returns the ID of the new custom key store. For help with failures, see Troubleshoot a Custom Key Store (https://docs.aws.amazon.com/kms/latest/developerguide/fix-keystore.html) in the AWS KMS Developer Guide.

Returns awserr.Error for service API and SDK errors. Use runtime type assertions with awserr.Error's Code and Message methods to get detailed information about the error.

See the AWS API reference guide for AWS Key Management Service's API operation CreateCustomKeyStore for usage and error information.

Returned Error Codes:

  • ErrCodeCloudHsmClusterInUseException "CloudHsmClusterInUseException" The request was rejected because the specified AWS CloudHSM cluster is already associated with a custom key store or it shares a backup history with a cluster that is associated with a custom key store. Each custom key store must be associated with a different AWS CloudHSM cluster.

Clusters that share a backup history have the same cluster certificate. To view the cluster certificate of a cluster, use the DescribeClusters (http://docs.aws.amazon.com/cloudhsm/latest/APIReference/API_DescribeClusters.html) operation.
  • ErrCodeCustomKeyStoreNameInUseException "CustomKeyStoreNameInUseException" The request was rejected because the specified custom key store name is already assigned to another custom key store in the account. Try again with a custom key store name that is unique in the account.

  • ErrCodeCloudHsmClusterNotFoundException "CloudHsmClusterNotFoundException" The request was rejected because AWS KMS cannot find the AWS CloudHSM cluster with the specified cluster ID. Retry the request with a different cluster ID.

  • ErrCodeInternalException "KMSInternalException" The request was rejected because an internal exception occurred. The request can be retried.

  • ErrCodeCloudHsmClusterNotActiveException "CloudHsmClusterNotActiveException" The request was rejected because the AWS CloudHSM cluster that is associated with the custom key store is not active. Initialize and activate the cluster and try the command again. For detailed instructions, see Getting Started

(http://docs.aws.amazon.com/cloudhsm/latest/userguide/getting-started.html) in the AWS CloudHSM User Guide.
  • ErrCodeIncorrectTrustAnchorException "IncorrectTrustAnchorException" The request was rejected because the trust anchor certificate in the request is not the trust anchor certificate for the specified AWS CloudHSM cluster.

When you initialize the cluster (http://docs.aws.amazon.com/cloudhsm/latest/userguide/initialize-cluster.html#sign-csr), you create the trust anchor certificate and save it in the customerCA.crt file.
  • ErrCodeCloudHsmClusterInvalidConfigurationException "CloudHsmClusterInvalidConfigurationException" The request was rejected because the associated AWS CloudHSM cluster did not meet the configuration requirements for a custom key store. The cluster must be configured with private subnets in at least two different Availability Zones in the Region. Also, it must contain at least as many HSMs as the operation requires.

For the CreateCustomKeyStore, UpdateCustomKeyStore, and CreateKey operations, the AWS CloudHSM cluster must have at least two active HSMs, each in a different Availability Zone. For the ConnectCustomKeyStore operation, the AWS CloudHSM must contain at least one active HSM. For information about creating a private subnet for a AWS CloudHSM cluster, see Create a Private Subnet (http://docs.aws.amazon.com/cloudhsm/latest/userguide/create-subnets.html) in the AWS CloudHSM User Guide. To add HSMs, use the AWS CloudHSM CreateHsm (http://docs.aws.amazon.com/cloudhsm/latest/APIReference/API_CreateHsm.html) operation.

See also, https://docs.aws.amazon.com/goto/WebAPI/kms-2014-11-01/CreateCustomKeyStore

CreateCustomKeyStoreRequest

func (c *KMS) CreateCustomKeyStoreRequest(input *CreateCustomKeyStoreInput) (req *request.Request, output *CreateCustomKeyStoreOutput)

CreateCustomKeyStoreRequest generates a "aws/request.Request" representing the client's request for the CreateCustomKeyStore operation. The "output" return value will be populated with the request's response once the request completes successfully.

Use "Send" method on the returned Request to send the API call to the service. the "output" return value is not valid until after Send returns without error.

See CreateCustomKeyStore for more information on using the CreateCustomKeyStore API call, and error handling.

This method is useful when you want to inject custom logic or configuration into the SDK's request lifecycle. Such as custom headers, or retry logic.

// Example sending a request using the CreateCustomKeyStoreRequest method. req, resp := client.CreateCustomKeyStoreRequest(params) err := req.Send() if err == nil { // resp is now filled fmt.Println(resp) }

See also, https://docs.aws.amazon.com/goto/WebAPI/kms-2014-11-01/CreateCustomKeyStore

CreateCustomKeyStoreWithContext

func (c *KMS) CreateCustomKeyStoreWithContext(ctx aws.Context, input *CreateCustomKeyStoreInput, opts ...request.Option) (*CreateCustomKeyStoreOutput, error)

CreateCustomKeyStoreWithContext is the same as CreateCustomKeyStore with the addition of the ability to pass a context and additional request options.

See CreateCustomKeyStore for details on how to use this API operation.

The context must be non-nil and will be used for request cancellation. If the context is nil a panic will occur. In the future the SDK may create sub-contexts for http.Requests. See https://golang.org/pkg/context/ for more information on using Contexts.

See Also

For more information about using this API, see AWS API Documentation.

CreateGrant

func (c *KMS) CreateGrant(input *CreateGrantInput) (*CreateGrantOutput, error)

CreateGrant API operation for AWS Key Management Service.

Adds a grant to a customer master key (CMK). The grant specifies who can use the CMK and under what conditions. When setting permissions, grants are an alternative to key policies.

To perform this operation on a CMK in a different AWS account, specify the key ARN in the value of the KeyId parameter. For more information about grants, see Grants (https://docs.aws.amazon.com/kms/latest/developerguide/grants.html) in the AWS Key Management Service Developer Guide.

The result of this operation varies with the key state of the CMK. For details, see How Key State Affects Use of a Customer Master Key (https://docs.aws.amazon.com/kms/latest/developerguide/key-state.html) in the AWS Key Management Service Developer Guide.

Returns awserr.Error for service API and SDK errors. Use runtime type assertions with awserr.Error's Code and Message methods to get detailed information about the error.

See the AWS API reference guide for AWS Key Management Service's API operation CreateGrant for usage and error information.

Returned Error Codes:

  • ErrCodeNotFoundException "NotFoundException" The request was rejected because the specified entity or resource could not be found.

  • ErrCodeDisabledException "DisabledException" The request was rejected because the specified CMK is not enabled.

  • ErrCodeDependencyTimeoutException "DependencyTimeoutException" The system timed out while trying to fulfill the request. The request can be retried.

  • ErrCodeInvalidArnException "InvalidArnException" The request was rejected because a specified ARN was not valid.

  • ErrCodeInternalException "KMSInternalException" The request was rejected because an internal exception occurred. The request can be retried.

  • ErrCodeInvalidGrantTokenException "InvalidGrantTokenException" The request was rejected because the specified grant token is not valid.

  • ErrCodeInvalidStateException "KMSInvalidStateException" The request was rejected because the state of the specified resource is not valid for this request.

For more information about how key state affects the use of a CMK, see How Key State Affects Use of a Customer Master Key (http://docs.aws.amazon.com/kms/latest/developerguide/key-state.html) in the AWS Key Management Service Developer Guide.

See also, https://docs.aws.amazon.com/goto/WebAPI/kms-2014-11-01/CreateGrant

Example

KMS CreateGrant shared00

To create a grant

The following example creates a grant that allows the specified IAM role to encrypt data with the specified customer master key (CMK).

{ svc := kms.New(session.New()) input := &kms.CreateGrantInput{ GranteePrincipal: aws.String("arn:aws:iam::111122223333:role/ExampleRole"), KeyId: aws.String("arn:aws:kms:us-east-2:444455556666:key/1234abcd-12ab-34cd-56ef-1234567890ab"), Operations: []*string{ aws.String("Encrypt"), aws.String("Decrypt"), }, } result, err := svc.CreateGrant(input) if err != nil { if aerr, ok := err.(awserr.Error); ok { switch aerr.Code() { case kms.ErrCodeNotFoundException: fmt.Println(kms.ErrCodeNotFoundException, aerr.Error()) case kms.ErrCodeDisabledException: fmt.Println(kms.ErrCodeDisabledException, aerr.Error()) case kms.ErrCodeDependencyTimeoutException: fmt.Println(kms.ErrCodeDependencyTimeoutException, aerr.Error()) case kms.ErrCodeInvalidArnException: fmt.Println(kms.ErrCodeInvalidArnException, aerr.Error()) case kms.ErrCodeInternalException: fmt.Println(kms.ErrCodeInternalException, aerr.Error()) case kms.ErrCodeInvalidGrantTokenException: fmt.Println(kms.ErrCodeInvalidGrantTokenException, aerr.Error()) case kms.ErrCodeLimitExceededException: fmt.Println(kms.ErrCodeLimitExceededException, aerr.Error()) case kms.ErrCodeInvalidStateException: fmt.Println(kms.ErrCodeInvalidStateException, aerr.Error()) default: fmt.Println(aerr.Error()) } } else { fmt.Println(err.Error()) } return } fmt.Println(result) }

CreateGrantRequest

func (c *KMS) CreateGrantRequest(input *CreateGrantInput) (req *request.Request, output *CreateGrantOutput)

CreateGrantRequest generates a "aws/request.Request" representing the client's request for the CreateGrant operation. The "output" return value will be populated with the request's response once the request completes successfully.

Use "Send" method on the returned Request to send the API call to the service. the "output" return value is not valid until after Send returns without error.

See CreateGrant for more information on using the CreateGrant API call, and error handling.

This method is useful when you want to inject custom logic or configuration into the SDK's request lifecycle. Such as custom headers, or retry logic.

// Example sending a request using the CreateGrantRequest method. req, resp := client.CreateGrantRequest(params) err := req.Send() if err == nil { // resp is now filled fmt.Println(resp) }

See also, https://docs.aws.amazon.com/goto/WebAPI/kms-2014-11-01/CreateGrant

CreateGrantWithContext

func (c *KMS) CreateGrantWithContext(ctx aws.Context, input *CreateGrantInput, opts ...request.Option) (*CreateGrantOutput, error)

CreateGrantWithContext is the same as CreateGrant with the addition of the ability to pass a context and additional request options.

See CreateGrant for details on how to use this API operation.

The context must be non-nil and will be used for request cancellation. If the context is nil a panic will occur. In the future the SDK may create sub-contexts for http.Requests. See https://golang.org/pkg/context/ for more information on using Contexts.

See Also

For more information about using this API, see AWS API Documentation.

CreateKey

func (c *KMS) CreateKey(input *CreateKeyInput) (*CreateKeyOutput, error)

CreateKey API operation for AWS Key Management Service.

Creates a customer master key (CMK) in the caller's AWS account.

You can use a CMK to encrypt small amounts of data (4 KiB or less) directly, but CMKs are more commonly used to encrypt data keys, which are used to encrypt raw data. For more information about data keys and the difference between CMKs and data keys, see the following:

  • The GenerateDataKey operation

If you plan to import key material (https://docs.aws.amazon.com/kms/latest/developerguide/importing-keys.html), use the Origin parameter with a value of EXTERNAL to create a CMK with no key material.

To create a CMK in a custom key store (https://docs.aws.amazon.com/kms/latest/developerguide/key-store-overview.html), use CustomKeyStoreId parameter to specify the custom key store. You must also use the Origin parameter with a value of AWS_CLOUDHSM. The AWS CloudHSM cluster that is associated with the custom key store must have at least two active HSMs, each in a different Availability Zone in the Region.

You cannot use this operation to create a CMK in a different AWS account.

Returns awserr.Error for service API and SDK errors. Use runtime type assertions with awserr.Error's Code and Message methods to get detailed information about the error.

See the AWS API reference guide for AWS Key Management Service's API operation CreateKey for usage and error information.

Returned Error Codes:

  • ErrCodeMalformedPolicyDocumentException "MalformedPolicyDocumentException" The request was rejected because the specified policy is not syntactically or semantically correct.

  • ErrCodeDependencyTimeoutException "DependencyTimeoutException" The system timed out while trying to fulfill the request. The request can be retried.

  • ErrCodeInvalidArnException "InvalidArnException" The request was rejected because a specified ARN was not valid.

  • ErrCodeUnsupportedOperationException "UnsupportedOperationException" The request was rejected because a specified parameter is not supported or a specified resource is not valid for this operation.

  • ErrCodeInternalException "KMSInternalException" The request was rejected because an internal exception occurred. The request can be retried.

  • ErrCodeTagException "TagException" The request was rejected because one or more tags are not valid.

  • ErrCodeCustomKeyStoreNotFoundException "CustomKeyStoreNotFoundException" The request was rejected because AWS KMS cannot find a custom key store with the specified key store name or ID.

  • ErrCodeCustomKeyStoreInvalidStateException "CustomKeyStoreInvalidStateException" The request was rejected because of the ConnectionState of the custom key store. To get the ConnectionState of a custom key store, use the DescribeCustomKeyStores operation.

This exception is thrown under the following conditions:
  • You requested the CreateKey or GenerateRandom operation in a custom key store that is not connected. These operations are valid only when the custom key store ConnectionState is CONNECTED.

  • You requested the UpdateCustomKeyStore or DeleteCustomKeyStore operation on a custom key store that is not disconnected. This operation is valid only when the custom key store ConnectionState is DISCONNECTED.

  • You requested the ConnectCustomKeyStore operation on a custom key store with a ConnectionState of DISCONNECTING or FAILED. This operation is valid for all other ConnectionState values.

  • ErrCodeCloudHsmClusterInvalidConfigurationException "CloudHsmClusterInvalidConfigurationException" The request was rejected because the associated AWS CloudHSM cluster did not meet the configuration requirements for a custom key store. The cluster must be configured with private subnets in at least two different Availability Zones in the Region. Also, it must contain at least as many HSMs as the operation requires.

For the CreateCustomKeyStore, UpdateCustomKeyStore, and CreateKey operations, the AWS CloudHSM cluster must have at least two active HSMs, each in a different Availability Zone. For the ConnectCustomKeyStore operation, the AWS CloudHSM must contain at least one active HSM. For information about creating a private subnet for a AWS CloudHSM cluster, see Create a Private Subnet (http://docs.aws.amazon.com/cloudhsm/latest/userguide/create-subnets.html) in the AWS CloudHSM User Guide. To add HSMs, use the AWS CloudHSM CreateHsm (http://docs.aws.amazon.com/cloudhsm/latest/APIReference/API_CreateHsm.html) operation.

See also, https://docs.aws.amazon.com/goto/WebAPI/kms-2014-11-01/CreateKey

Example

KMS CreateKey shared00

To create a customer master key (CMK)

The following example creates a CMK.

{ svc := kms.New(session.New()) input := &kms.CreateKeyInput{ Tags: []*kms.Tag{ { TagKey: aws.String("CreatedBy"), TagValue: aws.String("ExampleUser"), }, }, } result, err := svc.CreateKey(input) if err != nil { if aerr, ok := err.(awserr.Error); ok { switch aerr.Code() { case kms.ErrCodeMalformedPolicyDocumentException: fmt.Println(kms.ErrCodeMalformedPolicyDocumentException, aerr.Error()) case kms.ErrCodeDependencyTimeoutException: fmt.Println(kms.ErrCodeDependencyTimeoutException, aerr.Error()) case kms.ErrCodeInvalidArnException: fmt.Println(kms.ErrCodeInvalidArnException, aerr.Error()) case kms.ErrCodeUnsupportedOperationException: fmt.Println(kms.ErrCodeUnsupportedOperationException, aerr.Error()) case kms.ErrCodeInternalException: fmt.Println(kms.ErrCodeInternalException, aerr.Error()) case kms.ErrCodeLimitExceededException: fmt.Println(kms.ErrCodeLimitExceededException, aerr.Error()) case kms.ErrCodeTagException: fmt.Println(kms.ErrCodeTagException, aerr.Error()) case kms.ErrCodeCustomKeyStoreNotFoundException: fmt.Println(kms.ErrCodeCustomKeyStoreNotFoundException, aerr.Error()) case kms.ErrCodeCustomKeyStoreInvalidStateException: fmt.Println(kms.ErrCodeCustomKeyStoreInvalidStateException, aerr.Error()) case kms.ErrCodeCloudHsmClusterInvalidConfigurationException: fmt.Println(kms.ErrCodeCloudHsmClusterInvalidConfigurationException, aerr.Error()) default: fmt.Println(aerr.Error()) } } else { fmt.Println(err.Error()) } return } fmt.Println(result) }

CreateKeyRequest

func (c *KMS) CreateKeyRequest(input *CreateKeyInput) (req *request.Request, output *CreateKeyOutput)

CreateKeyRequest generates a "aws/request.Request" representing the client's request for the CreateKey operation. The "output" return value will be populated with the request's response once the request completes successfully.

Use "Send" method on the returned Request to send the API call to the service. the "output" return value is not valid until after Send returns without error.

See CreateKey for more information on using the CreateKey API call, and error handling.

This method is useful when you want to inject custom logic or configuration into the SDK's request lifecycle. Such as custom headers, or retry logic.

// Example sending a request using the CreateKeyRequest method. req, resp := client.CreateKeyRequest(params) err := req.Send() if err == nil { // resp is now filled fmt.Println(resp) }

See also, https://docs.aws.amazon.com/goto/WebAPI/kms-2014-11-01/CreateKey

CreateKeyWithContext

func (c *KMS) CreateKeyWithContext(ctx aws.Context, input *CreateKeyInput, opts ...request.Option) (*CreateKeyOutput, error)

CreateKeyWithContext is the same as CreateKey with the addition of the ability to pass a context and additional request options.

See CreateKey for details on how to use this API operation.

The context must be non-nil and will be used for request cancellation. If the context is nil a panic will occur. In the future the SDK may create sub-contexts for http.Requests. See https://golang.org/pkg/context/ for more information on using Contexts.

See Also

For more information about using this API, see AWS API Documentation.

Decrypt

func (c *KMS) Decrypt(input *DecryptInput) (*DecryptOutput, error)

Decrypt API operation for AWS Key Management Service.

Decrypts ciphertext. Ciphertext is plaintext that has been previously encrypted by using any of the following operations:

  • GenerateDataKey

  • GenerateDataKeyWithoutPlaintext

  • Encrypt

Note that if a caller has been granted access permissions to all keys (through, for example, IAM user policies that grant Decrypt permission on all resources), then ciphertext encrypted by using keys in other accounts where the key grants access to the caller can be decrypted. To remedy this, we recommend that you do not grant Decrypt access in an IAM user policy. Instead grant Decrypt access only in key policies. If you must grant Decrypt access in an IAM user policy, you should scope the resource to specific keys or to specific trusted accounts.

The result of this operation varies with the key state of the CMK. For details, see How Key State Affects Use of a Customer Master Key (https://docs.aws.amazon.com/kms/latest/developerguide/key-state.html) in the AWS Key Management Service Developer Guide.

Returns awserr.Error for service API and SDK errors. Use runtime type assertions with awserr.Error's Code and Message methods to get detailed information about the error.

See the AWS API reference guide for AWS Key Management Service's API operation Decrypt for usage and error information.

Returned Error Codes:

  • ErrCodeNotFoundException "NotFoundException" The request was rejected because the specified entity or resource could not be found.

  • ErrCodeDisabledException "DisabledException" The request was rejected because the specified CMK is not enabled.

  • ErrCodeInvalidCiphertextException "InvalidCiphertextException" The request was rejected because the specified ciphertext, or additional authenticated data incorporated into the ciphertext, such as the encryption context, is corrupted, missing, or otherwise invalid.

  • ErrCodeKeyUnavailableException "KeyUnavailableException" The request was rejected because the specified CMK was not available. The request can be retried.

  • ErrCodeDependencyTimeoutException "DependencyTimeoutException" The system timed out while trying to fulfill the request. The request can be retried.

  • ErrCodeInvalidGrantTokenException "InvalidGrantTokenException" The request was rejected because the specified grant token is not valid.

  • ErrCodeInternalException "KMSInternalException" The request was rejected because an internal exception occurred. The request can be retried.

  • ErrCodeInvalidStateException "KMSInvalidStateException" The request was rejected because the state of the specified resource is not valid for this request.

For more information about how key state affects the use of a CMK, see How Key State Affects Use of a Customer Master Key (http://docs.aws.amazon.com/kms/latest/developerguide/key-state.html) in the AWS Key Management Service Developer Guide.

See also, https://docs.aws.amazon.com/goto/WebAPI/kms-2014-11-01/Decrypt

Example

KMS Decrypt shared00

To decrypt data

The following example decrypts data that was encrypted with a customer master key (CMK) in AWS KMS.

{ svc := kms.New(session.New()) input := &kms.DecryptInput{ CiphertextBlob: []byte("<binary data>"), } result, err := svc.Decrypt(input) if err != nil { if aerr, ok := err.(awserr.Error); ok { switch aerr.Code() { case kms.ErrCodeNotFoundException: fmt.Println(kms.ErrCodeNotFoundException, aerr.Error()) case kms.ErrCodeDisabledException: fmt.Println(kms.ErrCodeDisabledException, aerr.Error()) case kms.ErrCodeInvalidCiphertextException: fmt.Println(kms.ErrCodeInvalidCiphertextException, aerr.Error()) case kms.ErrCodeKeyUnavailableException: fmt.Println(kms.ErrCodeKeyUnavailableException, aerr.Error()) case kms.ErrCodeDependencyTimeoutException: fmt.Println(kms.ErrCodeDependencyTimeoutException, aerr.Error()) case kms.ErrCodeInvalidGrantTokenException: fmt.Println(kms.ErrCodeInvalidGrantTokenException, aerr.Error()) case kms.ErrCodeInternalException: fmt.Println(kms.ErrCodeInternalException, aerr.Error()) case kms.ErrCodeInvalidStateException: fmt.Println(kms.ErrCodeInvalidStateException, aerr.Error()) default: fmt.Println(aerr.Error()) } } else { fmt.Println(err.Error()) } return } fmt.Println(result) }

DecryptRequest

func (c *KMS) DecryptRequest(input *DecryptInput) (req *request.Request, output *DecryptOutput)

DecryptRequest generates a "aws/request.Request" representing the client's request for the Decrypt operation. The "output" return value will be populated with the request's response once the request completes successfully.

Use "Send" method on the returned Request to send the API call to the service. the "output" return value is not valid until after Send returns without error.

See Decrypt for more information on using the Decrypt API call, and error handling.

This method is useful when you want to inject custom logic or configuration into the SDK's request lifecycle. Such as custom headers, or retry logic.

// Example sending a request using the DecryptRequest method. req, resp := client.DecryptRequest(params) err := req.Send() if err == nil { // resp is now filled fmt.Println(resp) }

See also, https://docs.aws.amazon.com/goto/WebAPI/kms-2014-11-01/Decrypt

DecryptWithContext

func (c *KMS) DecryptWithContext(ctx aws.Context, input *DecryptInput, opts ...request.Option) (*DecryptOutput, error)

DecryptWithContext is the same as Decrypt with the addition of the ability to pass a context and additional request options.

See Decrypt for details on how to use this API operation.

The context must be non-nil and will be used for request cancellation. If the context is nil a panic will occur. In the future the SDK may create sub-contexts for http.Requests. See https://golang.org/pkg/context/ for more information on using Contexts.

See Also

For more information about using this API, see AWS API Documentation.

DeleteAlias

func (c *KMS) DeleteAlias(input *DeleteAliasInput) (*DeleteAliasOutput, error)

DeleteAlias API operation for AWS Key Management Service.

Deletes the specified alias. You cannot perform this operation on an alias in a different AWS account.

Because an alias is not a property of a CMK, you can delete and change the aliases of a CMK without affecting the CMK. Also, aliases do not appear in the response from the DescribeKey operation. To get the aliases of all CMKs, use the ListAliases operation.

Each CMK can have multiple aliases. To change the alias of a CMK, use DeleteAlias to delete the current alias and CreateAlias to create a new alias. To associate an existing alias with a different customer master key (CMK), call UpdateAlias.

Returns awserr.Error for service API and SDK errors. Use runtime type assertions with awserr.Error's Code and Message methods to get detailed information about the error.

See the AWS API reference guide for AWS Key Management Service's API operation DeleteAlias for usage and error information.

Returned Error Codes:

  • ErrCodeDependencyTimeoutException "DependencyTimeoutException" The system timed out while trying to fulfill the request. The request can be retried.

  • ErrCodeNotFoundException "NotFoundException" The request was rejected because the specified entity or resource could not be found.

  • ErrCodeInternalException "KMSInternalException" The request was rejected because an internal exception occurred. The request can be retried.

  • ErrCodeInvalidStateException "KMSInvalidStateException" The request was rejected because the state of the specified resource is not valid for this request.

For more information about how key state affects the use of a CMK, see How Key State Affects Use of a Customer Master Key (http://docs.aws.amazon.com/kms/latest/developerguide/key-state.html) in the AWS Key Management Service Developer Guide.

See also, https://docs.aws.amazon.com/goto/WebAPI/kms-2014-11-01/DeleteAlias

Example

KMS DeleteAlias shared00

To delete an alias

The following example deletes the specified alias.

{ svc := kms.New(session.New()) input := &kms.DeleteAliasInput{ AliasName: aws.String("alias/ExampleAlias"), } result, err := svc.DeleteAlias(input) if err != nil { if aerr, ok := err.(awserr.Error); ok { switch aerr.Code() { case kms.ErrCodeDependencyTimeoutException: fmt.Println(kms.ErrCodeDependencyTimeoutException, aerr.Error()) case kms.ErrCodeNotFoundException: fmt.Println(kms.ErrCodeNotFoundException, aerr.Error()) case kms.ErrCodeInternalException: fmt.Println(kms.ErrCodeInternalException, aerr.Error()) case kms.ErrCodeInvalidStateException: fmt.Println(kms.ErrCodeInvalidStateException, aerr.Error()) default: fmt.Println(aerr.Error()) } } else { fmt.Println(err.Error()) } return } fmt.Println(result) }

DeleteAliasRequest

func (c *KMS) DeleteAliasRequest(input *DeleteAliasInput) (req *request.Request, output *DeleteAliasOutput)

DeleteAliasRequest generates a "aws/request.Request" representing the client's request for the DeleteAlias operation. The "output" return value will be populated with the request's response once the request completes successfully.

Use "Send" method on the returned Request to send the API call to the service. the "output" return value is not valid until after Send returns without error.

See DeleteAlias for more information on using the DeleteAlias API call, and error handling.

This method is useful when you want to inject custom logic or configuration into the SDK's request lifecycle. Such as custom headers, or retry logic.

// Example sending a request using the DeleteAliasRequest method. req, resp := client.DeleteAliasRequest(params) err := req.Send() if err == nil { // resp is now filled fmt.Println(resp) }

See also, https://docs.aws.amazon.com/goto/WebAPI/kms-2014-11-01/DeleteAlias

DeleteAliasWithContext

func (c *KMS) DeleteAliasWithContext(ctx aws.Context, input *DeleteAliasInput, opts ...request.Option) (*DeleteAliasOutput, error)

DeleteAliasWithContext is the same as DeleteAlias with the addition of the ability to pass a context and additional request options.

See DeleteAlias for details on how to use this API operation.

The context must be non-nil and will be used for request cancellation. If the context is nil a panic will occur. In the future the SDK may create sub-contexts for http.Requests. See https://golang.org/pkg/context/ for more information on using Contexts.

See Also

For more information about using this API, see AWS API Documentation.

DeleteCustomKeyStore

func (c *KMS) DeleteCustomKeyStore(input *DeleteCustomKeyStoreInput) (*DeleteCustomKeyStoreOutput, error)

DeleteCustomKeyStore API operation for AWS Key Management Service.

Deletes a custom key store (https://docs.aws.amazon.com/kms/latest/developerguide/key-store-overview.html). This operation does not delete the AWS CloudHSM cluster that is associated with the custom key store, or affect any users or keys in the cluster.

The custom key store that you delete cannot contain any AWS KMS customer master keys (CMKs) (https://docs.aws.amazon.com/kms/latest/developerguide/concepts.html#master_keys). Before deleting the key store, verify that you will never need to use any of the CMKs in the key store for any cryptographic operations. Then, use ScheduleKeyDeletion to delete the AWS KMS customer master keys (CMKs) from the key store. When the scheduled waiting period expires, the ScheduleKeyDeletion operation deletes the CMKs. Then it makes a best effort to delete the key material from the associated cluster. However, you might need to manually delete the orphaned key material (https://docs.aws.amazon.com/kms/latest/developerguide/fix-keystore.html#fix-keystore-orphaned-key) from the cluster and its backups.

After all CMKs are deleted from AWS KMS, use DisconnectCustomKeyStore to disconnect the key store from AWS KMS. Then, you can delete the custom key store.

Instead of deleting the custom key store, consider using DisconnectCustomKeyStore to disconnect it from AWS KMS. While the key store is disconnected, you cannot create or use the CMKs in the key store. But, you do not need to delete CMKs and you can reconnect a disconnected custom key store at any time.

If the operation succeeds, it returns a JSON object with no properties.

This operation is part of the Custom Key Store feature (https://docs.aws.amazon.com/kms/latest/developerguide/custom-key-store-overview.html) feature in AWS KMS, which combines the convenience and extensive integration of AWS KMS with the isolation and control of a single-tenant key store.

Returns awserr.Error for service API and SDK errors. Use runtime type assertions with awserr.Error's Code and Message methods to get detailed information about the error.

See the AWS API reference guide for AWS Key Management Service's API operation DeleteCustomKeyStore for usage and error information.

Returned Error Codes:

  • ErrCodeCustomKeyStoreHasCMKsException "CustomKeyStoreHasCMKsException" The request was rejected because the custom key store contains AWS KMS customer master keys (CMKs). After verifying that you do not need to use the CMKs, use the ScheduleKeyDeletion operation to delete the CMKs. After they are deleted, you can delete the custom key store.

  • ErrCodeCustomKeyStoreInvalidStateException "CustomKeyStoreInvalidStateException" The request was rejected because of the ConnectionState of the custom key store. To get the ConnectionState of a custom key store, use the DescribeCustomKeyStores operation.

This exception is thrown under the following conditions:
  • You requested the CreateKey or GenerateRandom operation in a custom key store that is not connected. These operations are valid only when the custom key store ConnectionState is CONNECTED.

  • You requested the UpdateCustomKeyStore or DeleteCustomKeyStore operation on a custom key store that is not disconnected. This operation is valid only when the custom key store ConnectionState is DISCONNECTED.

  • You requested the ConnectCustomKeyStore operation on a custom key store with a ConnectionState of DISCONNECTING or FAILED. This operation is valid for all other ConnectionState values.

  • ErrCodeCustomKeyStoreNotFoundException "CustomKeyStoreNotFoundException" The request was rejected because AWS KMS cannot find a custom key store with the specified key store name or ID.

  • ErrCodeInternalException "KMSInternalException" The request was rejected because an internal exception occurred. The request can be retried.

See also, https://docs.aws.amazon.com/goto/WebAPI/kms-2014-11-01/DeleteCustomKeyStore

DeleteCustomKeyStoreRequest

func (c *KMS) DeleteCustomKeyStoreRequest(input *DeleteCustomKeyStoreInput) (req *request.Request, output *DeleteCustomKeyStoreOutput)

DeleteCustomKeyStoreRequest generates a "aws/request.Request" representing the client's request for the DeleteCustomKeyStore operation. The "output" return value will be populated with the request's response once the request completes successfully.

Use "Send" method on the returned Request to send the API call to the service. the "output" return value is not valid until after Send returns without error.

See DeleteCustomKeyStore for more information on using the DeleteCustomKeyStore API call, and error handling.

This method is useful when you want to inject custom logic or configuration into the SDK's request lifecycle. Such as custom headers, or retry logic.

// Example sending a request using the DeleteCustomKeyStoreRequest method. req, resp := client.DeleteCustomKeyStoreRequest(params) err := req.Send() if err == nil { // resp is now filled fmt.Println(resp) }

See also, https://docs.aws.amazon.com/goto/WebAPI/kms-2014-11-01/DeleteCustomKeyStore

DeleteCustomKeyStoreWithContext

func (c *KMS) DeleteCustomKeyStoreWithContext(ctx aws.Context, input *DeleteCustomKeyStoreInput, opts ...request.Option) (*DeleteCustomKeyStoreOutput, error)

DeleteCustomKeyStoreWithContext is the same as DeleteCustomKeyStore with the addition of the ability to pass a context and additional request options.

See DeleteCustomKeyStore for details on how to use this API operation.

The context must be non-nil and will be used for request cancellation. If the context is nil a panic will occur. In the future the SDK may create sub-contexts for http.Requests. See https://golang.org/pkg/context/ for more information on using Contexts.

See Also

For more information about using this API, see AWS API Documentation.

DeleteImportedKeyMaterial

func (c *KMS) DeleteImportedKeyMaterial(input *DeleteImportedKeyMaterialInput) (*DeleteImportedKeyMaterialOutput, error)

DeleteImportedKeyMaterial API operation for AWS Key Management Service.

Deletes key material that you previously imported. This operation makes the specified customer master key (CMK) unusable. For more information about importing key material into AWS KMS, see Importing Key Material (https://docs.aws.amazon.com/kms/latest/developerguide/importing-keys.html) in the AWS Key Management Service Developer Guide. You cannot perform this operation on a CMK in a different AWS account.

When the specified CMK is in the PendingDeletion state, this operation does not change the CMK's state. Otherwise, it changes the CMK's state to PendingImport.

After you delete key material, you can use ImportKeyMaterial to reimport the same key material into the CMK.

The result of this operation varies with the key state of the CMK. For details, see How Key State Affects Use of a Customer Master Key (https://docs.aws.amazon.com/kms/latest/developerguide/key-state.html) in the AWS Key Management Service Developer Guide.

Returns awserr.Error for service API and SDK errors. Use runtime type assertions with awserr.Error's Code and Message methods to get detailed information about the error.

See the AWS API reference guide for AWS Key Management Service's API operation DeleteImportedKeyMaterial for usage and error information.

Returned Error Codes:

  • ErrCodeInvalidArnException "InvalidArnException" The request was rejected because a specified ARN was not valid.

  • ErrCodeUnsupportedOperationException "UnsupportedOperationException" The request was rejected because a specified parameter is not supported or a specified resource is not valid for this operation.

  • ErrCodeDependencyTimeoutException "DependencyTimeoutException" The system timed out while trying to fulfill the request. The request can be retried.

  • ErrCodeNotFoundException "NotFoundException" The request was rejected because the specified entity or resource could not be found.

  • ErrCodeInternalException "KMSInternalException" The request was rejected because an internal exception occurred. The request can be retried.

  • ErrCodeInvalidStateException "KMSInvalidStateException" The request was rejected because the state of the specified resource is not valid for this request.

For more information about how key state affects the use of a CMK, see How Key State Affects Use of a Customer Master Key (http://docs.aws.amazon.com/kms/latest/developerguide/key-state.html) in the AWS Key Management Service Developer Guide.

See also, https://docs.aws.amazon.com/goto/WebAPI/kms-2014-11-01/DeleteImportedKeyMaterial

Example

KMS DeleteImportedKeyMaterial shared00

To delete imported key material

The following example deletes the imported key material from the specified customer master key (CMK).

{ svc := kms.New(session.New()) input := &kms.DeleteImportedKeyMaterialInput{ KeyId: aws.String("1234abcd-12ab-34cd-56ef-1234567890ab"), } result, err := svc.DeleteImportedKeyMaterial(input) if err != nil { if aerr, ok := err.(awserr.Error); ok { switch aerr.Code() { case kms.ErrCodeInvalidArnException: fmt.Println(kms.ErrCodeInvalidArnException, aerr.Error()) case kms.ErrCodeUnsupportedOperationException: fmt.Println(kms.ErrCodeUnsupportedOperationException, aerr.Error()) case kms.ErrCodeDependencyTimeoutException: fmt.Println(kms.ErrCodeDependencyTimeoutException, aerr.Error()) case kms.ErrCodeNotFoundException: fmt.Println(kms.ErrCodeNotFoundException, aerr.Error()) case kms.ErrCodeInternalException: fmt.Println(kms.ErrCodeInternalException, aerr.Error()) case kms.ErrCodeInvalidStateException: fmt.Println(kms.ErrCodeInvalidStateException, aerr.Error()) default: fmt.Println(aerr.Error()) } } else { fmt.Println(err.Error()) } return } fmt.Println(result) }

DeleteImportedKeyMaterialRequest

func (c *KMS) DeleteImportedKeyMaterialRequest(input *DeleteImportedKeyMaterialInput) (req *request.Request, output *DeleteImportedKeyMaterialOutput)

DeleteImportedKeyMaterialRequest generates a "aws/request.Request" representing the client's request for the DeleteImportedKeyMaterial operation. The "output" return value will be populated with the request's response once the request completes successfully.

Use "Send" method on the returned Request to send the API call to the service. the "output" return value is not valid until after Send returns without error.

See DeleteImportedKeyMaterial for more information on using the DeleteImportedKeyMaterial API call, and error handling.

This method is useful when you want to inject custom logic or configuration into the SDK's request lifecycle. Such as custom headers, or retry logic.

// Example sending a request using the DeleteImportedKeyMaterialRequest method. req, resp := client.DeleteImportedKeyMaterialRequest(params) err := req.Send() if err == nil { // resp is now filled fmt.Println(resp) }

See also, https://docs.aws.amazon.com/goto/WebAPI/kms-2014-11-01/DeleteImportedKeyMaterial

DeleteImportedKeyMaterialWithContext

func (c *KMS) DeleteImportedKeyMaterialWithContext(ctx aws.Context, input *DeleteImportedKeyMaterialInput, opts ...request.Option) (*DeleteImportedKeyMaterialOutput, error)

DeleteImportedKeyMaterialWithContext is the same as DeleteImportedKeyMaterial with the addition of the ability to pass a context and additional request options.

See DeleteImportedKeyMaterial for details on how to use this API operation.

The context must be non-nil and will be used for request cancellation. If the context is nil a panic will occur. In the future the SDK may create sub-contexts for http.Requests. See https://golang.org/pkg/context/ for more information on using Contexts.

See Also

For more information about using this API, see AWS API Documentation.

DescribeCustomKeyStores

func (c *KMS) DescribeCustomKeyStores(input *DescribeCustomKeyStoresInput) (*DescribeCustomKeyStoresOutput, error)

DescribeCustomKeyStores API operation for AWS Key Management Service.

Gets information about custom key stores (https://docs.aws.amazon.com/kms/latest/developerguide/key-store-overview.html) in the account and region.

This operation is part of the Custom Key Store feature (https://docs.aws.amazon.com/kms/latest/developerguide/custom-key-store-overview.html) feature in AWS KMS, which combines the convenience and extensive integration of AWS KMS with the isolation and control of a single-tenant key store.

By default, this operation returns information about all custom key stores in the account and region. To get only information about a particular custom key store, use either the CustomKeyStoreName or CustomKeyStoreId parameter (but not both).

To determine whether the custom key store is connected to its AWS CloudHSM cluster, use the ConnectionState element in the response. If an attempt to connect the custom key store failed, the ConnectionState value is FAILED and the ConnectionErrorCode element in the response indicates the cause of the failure. For help interpreting the ConnectionErrorCode, see CustomKeyStoresListEntry.

Custom key stores have a DISCONNECTED connection state if the key store has never been connected or you use the DisconnectCustomKeyStore operation to disconnect it. If your custom key store state is CONNECTED but you are having trouble using it, make sure that its associated AWS CloudHSM cluster is active and contains the minimum number of HSMs required for the operation, if any.

For help repairing your custom key store, see the Troubleshooting Custom Key Stores (https://docs.aws.amazon.com/kms/latest/developerguide/fix-keystore-html) topic in the AWS Key Management Service Developer Guide.

Returns awserr.Error for service API and SDK errors. Use runtime type assertions with awserr.Error's Code and Message methods to get detailed information about the error.

See the AWS API reference guide for AWS Key Management Service's API operation DescribeCustomKeyStores for usage and error information.

Returned Error Codes:

  • ErrCodeCustomKeyStoreNotFoundException "CustomKeyStoreNotFoundException" The request was rejected because AWS KMS cannot find a custom key store with the specified key store name or ID.

  • ErrCodeInternalException "KMSInternalException" The request was rejected because an internal exception occurred. The request can be retried.

See also, https://docs.aws.amazon.com/goto/WebAPI/kms-2014-11-01/DescribeCustomKeyStores

DescribeCustomKeyStoresRequest

func (c *KMS) DescribeCustomKeyStoresRequest(input *DescribeCustomKeyStoresInput) (req *request.Request, output *DescribeCustomKeyStoresOutput)

DescribeCustomKeyStoresRequest generates a "aws/request.Request" representing the client's request for the DescribeCustomKeyStores operation. The "output" return value will be populated with the request's response once the request completes successfully.

Use "Send" method on the returned Request to send the API call to the service. the "output" return value is not valid until after Send returns without error.

See DescribeCustomKeyStores for more information on using the DescribeCustomKeyStores API call, and error handling.

This method is useful when you want to inject custom logic or configuration into the SDK's request lifecycle. Such as custom headers, or retry logic.

// Example sending a request using the DescribeCustomKeyStoresRequest method. req, resp := client.DescribeCustomKeyStoresRequest(params) err := req.Send() if err == nil { // resp is now filled fmt.Println(resp) }

See also, https://docs.aws.amazon.com/goto/WebAPI/kms-2014-11-01/DescribeCustomKeyStores

DescribeCustomKeyStoresWithContext

func (c *KMS) DescribeCustomKeyStoresWithContext(ctx aws.Context, input *DescribeCustomKeyStoresInput, opts ...request.Option) (*DescribeCustomKeyStoresOutput, error)

DescribeCustomKeyStoresWithContext is the same as DescribeCustomKeyStores with the addition of the ability to pass a context and additional request options.

See DescribeCustomKeyStores for details on how to use this API operation.

The context must be non-nil and will be used for request cancellation. If the context is nil a panic will occur. In the future the SDK may create sub-contexts for http.Requests. See https://golang.org/pkg/context/ for more information on using Contexts.

See Also

For more information about using this API, see AWS API Documentation.

DescribeKey

func (c *KMS) DescribeKey(input *DescribeKeyInput) (*DescribeKeyOutput, error)

DescribeKey API operation for AWS Key Management Service.

Provides detailed information about the specified customer master key (CMK).

If you use DescribeKey on a predefined AWS alias, that is, an AWS alias with no key ID, AWS KMS associates the alias with an AWS managed CMK (https://docs.aws.amazon.com/kms/latest/developerguide/concepts.html#master_keys) and returns its KeyId and Arn in the response.

To perform this operation on a CMK in a different AWS account, specify the key ARN or alias ARN in the value of the KeyId parameter.

Returns awserr.Error for service API and SDK errors. Use runtime type assertions with awserr.Error's Code and Message methods to get detailed information about the error.

See the AWS API reference guide for AWS Key Management Service's API operation DescribeKey for usage and error information.

Returned Error Codes:

  • ErrCodeNotFoundException "NotFoundException" The request was rejected because the specified entity or resource could not be found.

  • ErrCodeInvalidArnException "InvalidArnException" The request was rejected because a specified ARN was not valid.

  • ErrCodeDependencyTimeoutException "DependencyTimeoutException" The system timed out while trying to fulfill the request. The request can be retried.

  • ErrCodeInternalException "KMSInternalException" The request was rejected because an internal exception occurred. The request can be retried.

See also, https://docs.aws.amazon.com/goto/WebAPI/kms-2014-11-01/DescribeKey

Example

KMS DescribeKey shared00

To obtain information about a customer master key (CMK)

The following example returns information (metadata) about the specified CMK.

{ svc := kms.New(session.New()) input := &kms.DescribeKeyInput{ KeyId: aws.String("1234abcd-12ab-34cd-56ef-1234567890ab"), } result, err := svc.DescribeKey(input) if err != nil { if aerr, ok := err.(awserr.Error); ok { switch aerr.Code() { case kms.ErrCodeNotFoundException: fmt.Println(kms.ErrCodeNotFoundException, aerr.Error()) case kms.ErrCodeInvalidArnException: fmt.Println(kms.ErrCodeInvalidArnException, aerr.Error()) case kms.ErrCodeDependencyTimeoutException: fmt.Println(kms.ErrCodeDependencyTimeoutException, aerr.Error()) case kms.ErrCodeInternalException: fmt.Println(kms.ErrCodeInternalException, aerr.Error()) default: fmt.Println(aerr.Error()) } } else { fmt.Println(err.Error()) } return } fmt.Println(result) }

DescribeKeyRequest

func (c *KMS) DescribeKeyRequest(input *DescribeKeyInput) (req *request.Request, output *DescribeKeyOutput)

DescribeKeyRequest generates a "aws/request.Request" representing the client's request for the DescribeKey operation. The "output" return value will be populated with the request's response once the request completes successfully.

Use "Send" method on the returned Request to send the API call to the service. the "output" return value is not valid until after Send returns without error.

See DescribeKey for more information on using the DescribeKey API call, and error handling.

This method is useful when you want to inject custom logic or configuration into the SDK's request lifecycle. Such as custom headers, or retry logic.

// Example sending a request using the DescribeKeyRequest method. req, resp := client.DescribeKeyRequest(params) err := req.Send() if err == nil { // resp is now filled fmt.Println(resp) }

See also, https://docs.aws.amazon.com/goto/WebAPI/kms-2014-11-01/DescribeKey

DescribeKeyWithContext

func (c *KMS) DescribeKeyWithContext(ctx aws.Context, input *DescribeKeyInput, opts ...request.Option) (*DescribeKeyOutput, error)

DescribeKeyWithContext is the same as DescribeKey with the addition of the ability to pass a context and additional request options.

See DescribeKey for details on how to use this API operation.

The context must be non-nil and will be used for request cancellation. If the context is nil a panic will occur. In the future the SDK may create sub-contexts for http.Requests. See https://golang.org/pkg/context/ for more information on using Contexts.

See Also

For more information about using this API, see AWS API Documentation.

DisableKey

func (c *KMS) DisableKey(input *DisableKeyInput) (*DisableKeyOutput, error)

DisableKey API operation for AWS Key Management Service.

Sets the state of a customer master key (CMK) to disabled, thereby preventing its use for cryptographic operations. You cannot perform this operation on a CMK in a different AWS account.

For more information about how key state affects the use of a CMK, see How Key State Affects the Use of a Customer Master Key (https://docs.aws.amazon.com/kms/latest/developerguide/key-state.html) in the AWS Key Management Service Developer Guide.

The result of this operation varies with the key state of the CMK. For details, see How Key State Affects Use of a Customer Master Key (https://docs.aws.amazon.com/kms/latest/developerguide/key-state.html) in the AWS Key Management Service Developer Guide.

Returns awserr.Error for service API and SDK errors. Use runtime type assertions with awserr.Error's Code and Message methods to get detailed information about the error.

See the AWS API reference guide for AWS Key Management Service's API operation DisableKey for usage and error information.

Returned Error Codes:

  • ErrCodeNotFoundException "NotFoundException" The request was rejected because the specified entity or resource could not be found.

  • ErrCodeInvalidArnException "InvalidArnException" The request was rejected because a specified ARN was not valid.

  • ErrCodeDependencyTimeoutException "DependencyTimeoutException" The system timed out while trying to fulfill the request. The request can be retried.

  • ErrCodeInternalException "KMSInternalException" The request was rejected because an internal exception occurred. The request can be retried.

  • ErrCodeInvalidStateException "KMSInvalidStateException" The request was rejected because the state of the specified resource is not valid for this request.

For more information about how key state affects the use of a CMK, see How Key State Affects Use of a Customer Master Key (http://docs.aws.amazon.com/kms/latest/developerguide/key-state.html) in the AWS Key Management Service Developer Guide.

See also, https://docs.aws.amazon.com/goto/WebAPI/kms-2014-11-01/DisableKey

Example

KMS DisableKey shared00

To disable a customer master key (CMK)

The following example disables the specified CMK.

{ svc := kms.New(session.New()) input := &kms.DisableKeyInput{ KeyId: aws.String("1234abcd-12ab-34cd-56ef-1234567890ab"), } result, err := svc.DisableKey(input) if err != nil { if aerr, ok := err.(awserr.Error); ok { switch aerr.Code() { case kms.ErrCodeNotFoundException: fmt.Println(kms.ErrCodeNotFoundException, aerr.Error()) case kms.ErrCodeInvalidArnException: fmt.Println(kms.ErrCodeInvalidArnException, aerr.Error()) case kms.ErrCodeDependencyTimeoutException: fmt.Println(kms.ErrCodeDependencyTimeoutException, aerr.Error()) case kms.ErrCodeInternalException: fmt.Println(kms.ErrCodeInternalException, aerr.Error()) case kms.ErrCodeInvalidStateException: fmt.Println(kms.ErrCodeInvalidStateException, aerr.Error()) default: fmt.Println(aerr.Error()) } } else { fmt.Println(err.Error()) } return } fmt.Println(result) }

DisableKeyRequest

func (c *KMS) DisableKeyRequest(input *DisableKeyInput) (req *request.Request, output *DisableKeyOutput)

DisableKeyRequest generates a "aws/request.Request" representing the client's request for the DisableKey operation. The "output" return value will be populated with the request's response once the request completes successfully.

Use "Send" method on the returned Request to send the API call to the service. the "output" return value is not valid until after Send returns without error.

See DisableKey for more information on using the DisableKey API call, and error handling.

This method is useful when you want to inject custom logic or configuration into the SDK's request lifecycle. Such as custom headers, or retry logic.

// Example sending a request using the DisableKeyRequest method. req, resp := client.DisableKeyRequest(params) err := req.Send() if err == nil { // resp is now filled fmt.Println(resp) }

See also, https://docs.aws.amazon.com/goto/WebAPI/kms-2014-11-01/DisableKey

DisableKeyRotation

func (c *KMS) DisableKeyRotation(input *DisableKeyRotationInput) (*DisableKeyRotationOutput, error)

DisableKeyRotation API operation for AWS Key Management Service.

Disables automatic rotation of the key material (https://docs.aws.amazon.com/kms/latest/developerguide/rotate-keys.html) for the specified customer master key (CMK). You cannot perform this operation on a CMK in a different AWS account.

The result of this operation varies with the key state of the CMK. For details, see How Key State Affects Use of a Customer Master Key (https://docs.aws.amazon.com/kms/latest/developerguide/key-state.html) in the AWS Key Management Service Developer Guide.

Returns awserr.Error for service API and SDK errors. Use runtime type assertions with awserr.Error's Code and Message methods to get detailed information about the error.

See the AWS API reference guide for AWS Key Management Service's API operation DisableKeyRotation for usage and error information.

Returned Error Codes:

  • ErrCodeNotFoundException "NotFoundException" The request was rejected because the specified entity or resource could not be found.

  • ErrCodeDisabledException "DisabledException" The request was rejected because the specified CMK is not enabled.

  • ErrCodeInvalidArnException "InvalidArnException" The request was rejected because a specified ARN was not valid.

  • ErrCodeDependencyTimeoutException "DependencyTimeoutException" The system timed out while trying to fulfill the request. The request can be retried.

  • ErrCodeInternalException "KMSInternalException" The request was rejected because an internal exception occurred. The request can be retried.

  • ErrCodeInvalidStateException "KMSInvalidStateException" The request was rejected because the state of the specified resource is not valid for this request.

For more information about how key state affects the use of a CMK, see How Key State Affects Use of a Customer Master Key (http://docs.aws.amazon.com/kms/latest/developerguide/key-state.html) in the AWS Key Management Service Developer Guide.
  • ErrCodeUnsupportedOperationException "UnsupportedOperationException" The request was rejected because a specified parameter is not supported or a specified resource is not valid for this operation.

See also, https://docs.aws.amazon.com/goto/WebAPI/kms-2014-11-01/DisableKeyRotation

Example

KMS DisableKeyRotation shared00

To disable automatic rotation of key material

The following example disables automatic annual rotation of the key material for the specified CMK.

{ svc := kms.New(session.New()) input := &kms.DisableKeyRotationInput{ KeyId: aws.String("1234abcd-12ab-34cd-56ef-1234567890ab"), } result, err := svc.DisableKeyRotation(input) if err != nil { if aerr, ok := err.(awserr.Error); ok { switch aerr.Code() { case kms.ErrCodeNotFoundException: fmt.Println(kms.ErrCodeNotFoundException, aerr.Error()) case kms.ErrCodeDisabledException: fmt.Println(kms.ErrCodeDisabledException, aerr.Error()) case kms.ErrCodeInvalidArnException: fmt.Println(kms.ErrCodeInvalidArnException, aerr.Error()) case kms.ErrCodeDependencyTimeoutException: fmt.Println(kms.ErrCodeDependencyTimeoutException, aerr.Error()) case kms.ErrCodeInternalException: fmt.Println(kms.ErrCodeInternalException, aerr.Error()) case kms.ErrCodeInvalidStateException: fmt.Println(kms.ErrCodeInvalidStateException, aerr.Error()) case kms.ErrCodeUnsupportedOperationException: fmt.Println(kms.ErrCodeUnsupportedOperationException, aerr.Error()) default: fmt.Println(aerr.Error()) } } else { fmt.Println(err.Error()) } return } fmt.Println(result) }

DisableKeyRotationRequest

func (c *KMS) DisableKeyRotationRequest(input *DisableKeyRotationInput) (req *request.Request, output *DisableKeyRotationOutput)

DisableKeyRotationRequest generates a "aws/request.Request" representing the client's request for the DisableKeyRotation operation. The "output" return value will be populated with the request's response once the request completes successfully.

Use "Send" method on the returned Request to send the API call to the service. the "output" return value is not valid until after Send returns without error.

See DisableKeyRotation for more information on using the DisableKeyRotation API call, and error handling.

This method is useful when you want to inject custom logic or configuration into the SDK's request lifecycle. Such as custom headers, or retry logic.

// Example sending a request using the DisableKeyRotationRequest method. req, resp := client.DisableKeyRotationRequest(params) err := req.Send() if err == nil { // resp is now filled fmt.Println(resp) }

See also, https://docs.aws.amazon.com/goto/WebAPI/kms-2014-11-01/DisableKeyRotation

DisableKeyRotationWithContext

func (c *KMS) DisableKeyRotationWithContext(ctx aws.Context, input *DisableKeyRotationInput, opts ...request.Option) (*DisableKeyRotationOutput, error)

DisableKeyRotationWithContext is the same as DisableKeyRotation with the addition of the ability to pass a context and additional request options.

See DisableKeyRotation for details on how to use this API operation.

The context must be non-nil and will be used for request cancellation. If the context is nil a panic will occur. In the future the SDK may create sub-contexts for http.Requests. See https://golang.org/pkg/context/ for more information on using Contexts.

See Also

For more information about using this API, see AWS API Documentation.

DisableKeyWithContext

func (c *KMS) DisableKeyWithContext(ctx aws.Context, input *DisableKeyInput, opts ...request.Option) (*DisableKeyOutput, error)

DisableKeyWithContext is the same as DisableKey with the addition of the ability to pass a context and additional request options.

See DisableKey for details on how to use this API operation.

The context must be non-nil and will be used for request cancellation. If the context is nil a panic will occur. In the future the SDK may create sub-contexts for http.Requests. See https://golang.org/pkg/context/ for more information on using Contexts.

See Also

For more information about using this API, see AWS API Documentation.

DisconnectCustomKeyStore

func (c *KMS) DisconnectCustomKeyStore(input *DisconnectCustomKeyStoreInput) (*DisconnectCustomKeyStoreOutput, error)

DisconnectCustomKeyStore API operation for AWS Key Management Service.

Disconnects the custom key store (https://docs.aws.amazon.com/kms/latest/developerguide/key-store-overview.html) from its associated AWS CloudHSM cluster. While a custom key store is disconnected, you can manage the custom key store and its customer master keys (CMKs), but you cannot create or use CMKs in the custom key store. You can reconnect the custom key store at any time.

While a custom key store is disconnected, all attempts to create customer master keys (CMKs) in the custom key store or to use existing CMKs in cryptographic operations will fail. This action can prevent users from storing and accessing sensitive data.

To find the connection state of a custom key store, use the DescribeCustomKeyStoresoperation. To reconnect a custom key store, use the ConnectCustomKeyStoreoperation.

If the operation succeeds, it returns a JSON object with no properties.

This operation is part of the Custom Key Store feature (https://docs.aws.amazon.com/kms/latest/developerguide/custom-key-store-overview.html)

Returns awserr.Error for service API and SDK errors. Use runtime type assertions with awserr.Error's Code and Message methods to get detailed information about the error.

See the AWS API reference guide for AWS Key Management Service's API operation DisconnectCustomKeyStore for usage and error information.

Returned Error Codes:

  • ErrCodeCustomKeyStoreInvalidStateException "CustomKeyStoreInvalidStateException" The request was rejected because of the ConnectionState of the custom key store. To get the ConnectionState of a custom key store, use the DescribeCustomKeyStores operation.

This exception is thrown under the following conditions:
  • You requested the CreateKey or GenerateRandom operation in a custom key store that is not connected. These operations are valid only when the custom key store ConnectionState is CONNECTED.

  • You requested the UpdateCustomKeyStore or DeleteCustomKeyStore operation on a custom key store that is not disconnected. This operation is valid only when the custom key store ConnectionState is DISCONNECTED.

  • You requested the ConnectCustomKeyStore operation on a custom key store with a ConnectionState of DISCONNECTING or FAILED. This operation is valid for all other ConnectionState values.

  • ErrCodeCustomKeyStoreNotFoundException "CustomKeyStoreNotFoundException" The request was rejected because AWS KMS cannot find a custom key store with the specified key store name or ID.

  • ErrCodeInternalException "KMSInternalException" The request was rejected because an internal exception occurred. The request can be retried.

See also, https://docs.aws.amazon.com/goto/WebAPI/kms-2014-11-01/DisconnectCustomKeyStore

DisconnectCustomKeyStoreRequest

func (c *KMS) DisconnectCustomKeyStoreRequest(input *DisconnectCustomKeyStoreInput) (req *request.Request, output *DisconnectCustomKeyStoreOutput)

DisconnectCustomKeyStoreRequest generates a "aws/request.Request" representing the client's request for the DisconnectCustomKeyStore operation. The "output" return value will be populated with the request's response once the request completes successfully.

Use "Send" method on the returned Request to send the API call to the service. the "output" return value is not valid until after Send returns without error.

See DisconnectCustomKeyStore for more information on using the DisconnectCustomKeyStore API call, and error handling.

This method is useful when you want to inject custom logic or configuration into the SDK's request lifecycle. Such as custom headers, or retry logic.

// Example sending a request using the DisconnectCustomKeyStoreRequest method. req, resp := client.DisconnectCustomKeyStoreRequest(params) err := req.Send() if err == nil { // resp is now filled fmt.Println(resp) }

See also, https://docs.aws.amazon.com/goto/WebAPI/kms-2014-11-01/DisconnectCustomKeyStore

DisconnectCustomKeyStoreWithContext

func (c *KMS) DisconnectCustomKeyStoreWithContext(ctx aws.Context, input *DisconnectCustomKeyStoreInput, opts ...request.Option) (*DisconnectCustomKeyStoreOutput, error)

DisconnectCustomKeyStoreWithContext is the same as DisconnectCustomKeyStore with the addition of the ability to pass a context and additional request options.

See DisconnectCustomKeyStore for details on how to use this API operation.

The context must be non-nil and will be used for request cancellation. If the context is nil a panic will occur. In the future the SDK may create sub-contexts for http.Requests. See https://golang.org/pkg/context/ for more information on using Contexts.

See Also

For more information about using this API, see AWS API Documentation.

EnableKey

func (c *KMS) EnableKey(input *EnableKeyInput) (*EnableKeyOutput, error)

EnableKey API operation for AWS Key Management Service.

Sets the key state of a customer master key (CMK) to enabled. This allows you to use the CMK for cryptographic operations. You cannot perform this operation on a CMK in a different AWS account.

The result of this operation varies with the key state of the CMK. For details, see How Key State Affects Use of a Customer Master Key (https://docs.aws.amazon.com/kms/latest/developerguide/key-state.html) in the AWS Key Management Service Developer Guide.

Returns awserr.Error for service API and SDK errors. Use runtime type assertions with awserr.Error's Code and Message methods to get detailed information about the error.

See the AWS API reference guide for AWS Key Management Service's API operation EnableKey for usage and error information.

Returned Error Codes:

  • ErrCodeNotFoundException "NotFoundException" The request was rejected because the specified entity or resource could not be found.

  • ErrCodeInvalidArnException "InvalidArnException" The request was rejected because a specified ARN was not valid.

  • ErrCodeDependencyTimeoutException "DependencyTimeoutException" The system timed out while trying to fulfill the request. The request can be retried.

  • ErrCodeInternalException "KMSInternalException" The request was rejected because an internal exception occurred. The request can be retried.

  • ErrCodeInvalidStateException "KMSInvalidStateException" The request was rejected because the state of the specified resource is not valid for this request.

For more information about how key state affects the use of a CMK, see How Key State Affects Use of a Customer Master Key (http://docs.aws.amazon.com/kms/latest/developerguide/key-state.html) in the AWS Key Management Service Developer Guide.

See also, https://docs.aws.amazon.com/goto/WebAPI/kms-2014-11-01/EnableKey

Example

KMS EnableKey shared00

To enable a customer master key (CMK)

The following example enables the specified CMK.

{ svc := kms.New(session.New()) input := &kms.EnableKeyInput{ KeyId: aws.String("1234abcd-12ab-34cd-56ef-1234567890ab"), } result, err := svc.EnableKey(input) if err != nil { if aerr, ok := err.(awserr.Error); ok { switch aerr.Code() { case kms.ErrCodeNotFoundException: fmt.Println(kms.ErrCodeNotFoundException, aerr.Error()) case kms.ErrCodeInvalidArnException: fmt.Println(kms.ErrCodeInvalidArnException, aerr.Error()) case kms.ErrCodeDependencyTimeoutException: fmt.Println(kms.ErrCodeDependencyTimeoutException, aerr.Error()) case kms.ErrCodeInternalException: fmt.Println(kms.ErrCodeInternalException, aerr.Error()) case kms.ErrCodeLimitExceededException: fmt.Println(kms.ErrCodeLimitExceededException, aerr.Error()) case kms.ErrCodeInvalidStateException: fmt.Println(kms.ErrCodeInvalidStateException, aerr.Error()) default: fmt.Println(aerr.Error()) } } else { fmt.Println(err.Error()) } return } fmt.Println(result) }

EnableKeyRequest

func (c *KMS) EnableKeyRequest(input *EnableKeyInput) (req *request.Request, output *EnableKeyOutput)

EnableKeyRequest generates a "aws/request.Request" representing the client's request for the EnableKey operation. The "output" return value will be populated with the request's response once the request completes successfully.

Use "Send" method on the returned Request to send the API call to the service. the "output" return value is not valid until after Send returns without error.

See EnableKey for more information on using the EnableKey API call, and error handling.

This method is useful when you want to inject custom logic or configuration into the SDK's request lifecycle. Such as custom headers, or retry logic.

// Example sending a request using the EnableKeyRequest method. req, resp := client.EnableKeyRequest(params) err := req.Send() if err == nil { // resp is now filled fmt.Println(resp) }

See also, https://docs.aws.amazon.com/goto/WebAPI/kms-2014-11-01/EnableKey

EnableKeyRotation

func (c *KMS) EnableKeyRotation(input *EnableKeyRotationInput) (*EnableKeyRotationOutput, error)

EnableKeyRotation API operation for AWS Key Management Service.

Enables automatic rotation of the key material (https://docs.aws.amazon.com/kms/latest/developerguide/rotate-keys.html) for the specified customer master key (CMK). You cannot perform this operation on a CMK in a different AWS account.

You cannot enable automatic rotation of CMKs with imported key material or CMKs in a custom key store (https://docs.aws.amazon.com/kms/latest/developerguide/key-store-overview.html).

The result of this operation varies with the key state of the CMK. For details, see How Key State Affects Use of a Customer Master Key (https://docs.aws.amazon.com/kms/latest/developerguide/key-state.html) in the AWS Key Management Service Developer Guide.

Returns awserr.Error for service API and SDK errors. Use runtime type assertions with awserr.Error's Code and Message methods to get detailed information about the error.

See the AWS API reference guide for AWS Key Management Service's API operation EnableKeyRotation for usage and error information.

Returned Error Codes:

  • ErrCodeNotFoundException "NotFoundException" The request was rejected because the specified entity or resource could not be found.

  • ErrCodeDisabledException "DisabledException" The request was rejected because the specified CMK is not enabled.

  • ErrCodeInvalidArnException "InvalidArnException" The request was rejected because a specified ARN was not valid.

  • ErrCodeDependencyTimeoutException "DependencyTimeoutException" The system timed out while trying to fulfill the request. The request can be retried.

  • ErrCodeInternalException "KMSInternalException" The request was rejected because an internal exception occurred. The request can be retried.

  • ErrCodeInvalidStateException "KMSInvalidStateException" The request was rejected because the state of the specified resource is not valid for this request.

For more information about how key state affects the use of a CMK, see How Key State Affects Use of a Customer Master Key (http://docs.aws.amazon.com/kms/latest/developerguide/key-state.html) in the AWS Key Management Service Developer Guide.
  • ErrCodeUnsupportedOperationException "UnsupportedOperationException" The request was rejected because a specified parameter is not supported or a specified resource is not valid for this operation.

See also, https://docs.aws.amazon.com/goto/WebAPI/kms-2014-11-01/EnableKeyRotation

Example

KMS EnableKeyRotation shared00

To enable automatic rotation of key material

The following example enables automatic annual rotation of the key material for the specified CMK.

{ svc := kms.New(session.New()) input := &kms.EnableKeyRotationInput{ KeyId: aws.String("1234abcd-12ab-34cd-56ef-1234567890ab"), } result, err := svc.EnableKeyRotation(input) if err != nil { if aerr, ok := err.(awserr.Error); ok { switch aerr.Code() { case kms.ErrCodeNotFoundException: fmt.Println(kms.ErrCodeNotFoundException, aerr.Error()) case kms.ErrCodeDisabledException: fmt.Println(kms.ErrCodeDisabledException, aerr.Error()) case kms.ErrCodeInvalidArnException: fmt.Println(kms.ErrCodeInvalidArnException, aerr.Error()) case kms.ErrCodeDependencyTimeoutException: fmt.Println(kms.ErrCodeDependencyTimeoutException, aerr.Error()) case kms.ErrCodeInternalException: fmt.Println(kms.ErrCodeInternalException, aerr.Error()) case kms.ErrCodeInvalidStateException: fmt.Println(kms.ErrCodeInvalidStateException, aerr.Error()) case kms.ErrCodeUnsupportedOperationException: fmt.Println(kms.ErrCodeUnsupportedOperationException, aerr.Error()) default: fmt.Println(aerr.Error()) } } else { fmt.Println(err.Error()) } return } fmt.Println(result) }

EnableKeyRotationRequest

func (c *KMS) EnableKeyRotationRequest(input *EnableKeyRotationInput) (req *request.Request, output *EnableKeyRotationOutput)

EnableKeyRotationRequest generates a "aws/request.Request" representing the client's request for the EnableKeyRotation operation. The "output" return value will be populated with the request's response once the request completes successfully.

Use "Send" method on the returned Request to send the API call to the service. the "output" return value is not valid until after Send returns without error.

See EnableKeyRotation for more information on using the EnableKeyRotation API call, and error handling.

This method is useful when you want to inject custom logic or configuration into the SDK's request lifecycle. Such as custom headers, or retry logic.

// Example sending a request using the EnableKeyRotationRequest method. req, resp := client.EnableKeyRotationRequest(params) err := req.Send() if err == nil { // resp is now filled fmt.Println(resp) }

See also, https://docs.aws.amazon.com/goto/WebAPI/kms-2014-11-01/EnableKeyRotation

EnableKeyRotationWithContext

func (c *KMS) EnableKeyRotationWithContext(ctx aws.Context, input *EnableKeyRotationInput, opts ...request.Option) (*EnableKeyRotationOutput, error)

EnableKeyRotationWithContext is the same as EnableKeyRotation with the addition of the ability to pass a context and additional request options.

See EnableKeyRotation for details on how to use this API operation.

The context must be non-nil and will be used for request cancellation. If the context is nil a panic will occur. In the future the SDK may create sub-contexts for http.Requests. See https://golang.org/pkg/context/ for more information on using Contexts.

See Also

For more information about using this API, see AWS API Documentation.

EnableKeyWithContext

func (c *KMS) EnableKeyWithContext(ctx aws.Context, input *EnableKeyInput, opts ...request.Option) (*EnableKeyOutput, error)

EnableKeyWithContext is the same as EnableKey with the addition of the ability to pass a context and additional request options.

See EnableKey for details on how to use this API operation.

The context must be non-nil and will be used for request cancellation. If the context is nil a panic will occur. In the future the SDK may create sub-contexts for http.Requests. See https://golang.org/pkg/context/ for more information on using Contexts.

See Also

For more information about using this API, see AWS API Documentation.

Encrypt

func (c *KMS) Encrypt(input *EncryptInput) (*EncryptOutput, error)

Encrypt API operation for AWS Key Management Service.

Encrypts plaintext into ciphertext by using a customer master key (CMK). The Encrypt operation has two primary use cases:

  • You can encrypt up to 4 kilobytes (4096 bytes) of arbitrary data such as an RSA key, a database password, or other sensitive information.

  • To move encrypted data from one AWS region to another, you can use this operation to encrypt in the new region the plaintext data key that was used to encrypt the data in the original region. This provides you with an encrypted copy of the data key that can be decrypted in the new region and used there to decrypt the encrypted data.

To perform this operation on a CMK in a different AWS account, specify the key ARN or alias ARN in the value of the KeyId parameter.

Unless you are moving encrypted data from one region to another, you don't use this operation to encrypt a generated data key within a region. To get data keys that are already encrypted, call the GenerateDataKey or GenerateDataKeyWithoutPlaintext operation. Data keys don't need to be encrypted again by calling Encrypt.

To encrypt data locally in your application, use the GenerateDataKey operation to return a plaintext data encryption key and a copy of the key encrypted under the CMK of your choosing.

The result of this operation varies with the key state of the CMK. For details, see How Key State Affects Use of a Customer Master Key (https://docs.aws.amazon.com/kms/latest/developerguide/key-state.html) in the AWS Key Management Service Developer Guide.

Returns awserr.Error for service API and SDK errors. Use runtime type assertions with awserr.Error's Code and Message methods to get detailed information about the error.

See the AWS API reference guide for AWS Key Management Service's API operation Encrypt for usage and error information.

Returned Error Codes:

  • ErrCodeNotFoundException "NotFoundException" The request was rejected because the specified entity or resource could not be found.

  • ErrCodeDisabledException "DisabledException" The request was rejected because the specified CMK is not enabled.

  • ErrCodeKeyUnavailableException "KeyUnavailableException" The request was rejected because the specified CMK was not available. The request can be retried.

  • ErrCodeDependencyTimeoutException "DependencyTimeoutException" The system timed out while trying to fulfill the request. The request can be retried.

  • ErrCodeInvalidKeyUsageException "InvalidKeyUsageException" The request was rejected because the specified KeySpec value is not valid.

  • ErrCodeInvalidGrantTokenException "InvalidGrantTokenException" The request was rejected because the specified grant token is not valid.

  • ErrCodeInternalException "KMSInternalException" The request was rejected because an internal exception occurred. The request can be retried.

  • ErrCodeInvalidStateException "KMSInvalidStateException" The request was rejected because the state of the specified resource is not valid for this request.

For more information about how key state affects the use of a CMK, see How Key State Affects Use of a Customer Master Key (http://docs.aws.amazon.com/kms/latest/developerguide/key-state.html) in the AWS Key Management Service Developer Guide.

See also, https://docs.aws.amazon.com/goto/WebAPI/kms-2014-11-01/Encrypt

Example

KMS Encrypt shared00

To encrypt data

The following example encrypts data with the specified customer master key (CMK).

{ svc := kms.New(session.New()) input := &kms.EncryptInput{ KeyId: aws.String("1234abcd-12ab-34cd-56ef-1234567890ab"), Plaintext: []byte("<binary data>"), } result, err := svc.Encrypt(input) if err != nil { if aerr, ok := err.(awserr.Error); ok { switch aerr.Code() { case kms.ErrCodeNotFoundException: fmt.Println(kms.ErrCodeNotFoundException, aerr.Error()) case kms.ErrCodeDisabledException: fmt.Println(kms.ErrCodeDisabledException, aerr.Error()) case kms.ErrCodeKeyUnavailableException: fmt.Println(kms.ErrCodeKeyUnavailableException, aerr.Error()) case kms.ErrCodeDependencyTimeoutException: fmt.Println(kms.ErrCodeDependencyTimeoutException, aerr.Error()) case kms.ErrCodeInvalidKeyUsageException: fmt.Println(kms.ErrCodeInvalidKeyUsageException, aerr.Error()) case kms.ErrCodeInvalidGrantTokenException: fmt.Println(kms.ErrCodeInvalidGrantTokenException, aerr.Error()) case kms.ErrCodeInternalException: fmt.Println(kms.ErrCodeInternalException, aerr.Error()) case kms.ErrCodeInvalidStateException: fmt.Println(kms.ErrCodeInvalidStateException, aerr.Error()) default: fmt.Println(aerr.Error()) } } else { fmt.Println(err.Error()) } return } fmt.Println(result) }

EncryptRequest

func (c *KMS) EncryptRequest(input *EncryptInput) (req *request.Request, output *EncryptOutput)

EncryptRequest generates a "aws/request.Request" representing the client's request for the Encrypt operation. The "output" return value will be populated with the request's response once the request completes successfully.

Use "Send" method on the returned Request to send the API call to the service. the "output" return value is not valid until after Send returns without error.

See Encrypt for more information on using the Encrypt API call, and error handling.

This method is useful when you want to inject custom logic or configuration into the SDK's request lifecycle. Such as custom headers, or retry logic.

// Example sending a request using the EncryptRequest method. req, resp := client.EncryptRequest(params) err := req.Send() if err == nil { // resp is now filled fmt.Println(resp) }

See also, https://docs.aws.amazon.com/goto/WebAPI/kms-2014-11-01/Encrypt

EncryptWithContext

func (c *KMS) EncryptWithContext(ctx aws.Context, input *EncryptInput, opts ...request.Option) (*EncryptOutput, error)

EncryptWithContext is the same as Encrypt with the addition of the ability to pass a context and additional request options.

See Encrypt for details on how to use this API operation.

The context must be non-nil and will be used for request cancellation. If the context is nil a panic will occur. In the future the SDK may create sub-contexts for http.Requests. See https://golang.org/pkg/context/ for more information on using Contexts.

See Also

For more information about using this API, see AWS API Documentation.

GenerateDataKey

func (c *KMS) GenerateDataKey(input *GenerateDataKeyInput) (*GenerateDataKeyOutput, error)

GenerateDataKey API operation for AWS Key Management Service.

Returns a data encryption key that you can use in your application to encrypt data locally.

You must specify the customer master key (CMK) under which to generate the data key. You must also specify the length of the data key using either the KeySpec or NumberOfBytes field. You must specify one field or the other, but not both. For common key lengths (128-bit and 256-bit symmetric keys), we recommend that you use KeySpec. To perform this operation on a CMK in a different AWS account, specify the key ARN or alias ARN in the value of the KeyId parameter.

This operation returns a plaintext copy of the data key in the Plaintext field of the response, and an encrypted copy of the data key in the CiphertextBlob field. The data key is encrypted under the CMK specified in the KeyId field of the request.

We recommend that you use the following pattern to encrypt data locally in your application:

Use this operation (GenerateDataKey) to get a data encryption key.

Use the plaintext data encryption key (returned in the Plaintext field of the response) to encrypt data locally, then erase the plaintext data key from memory.

Store the encrypted data key (returned in the CiphertextBlob field of the response) alongside the locally encrypted data.

To decrypt data locally:

Use the Decrypt operation to decrypt the encrypted data key into a plaintext copy of the data key.

Use the plaintext data key to decrypt data locally, then erase the plaintext data key from memory.

To return only an encrypted copy of the data key, use GenerateDataKeyWithoutPlaintext. To return a random byte string that is cryptographically secure, use GenerateRandom.

If you use the optional EncryptionContext field, you must store at least enough information to be able to reconstruct the full encryption context when you later send the ciphertext to the Decrypt operation. It is a good practice to choose an encryption context that you can reconstruct on the fly to better secure the ciphertext. For more information, see Encryption Context (https://docs.aws.amazon.com/kms/latest/developerguide/encryption-context.html) in the AWS Key Management Service Developer Guide.

The result of this operation varies with the key state of the CMK. For details, see How Key State Affects Use of a Customer Master Key (https://docs.aws.amazon.com/kms/latest/developerguide/key-state.html) in the AWS Key Management Service Developer Guide.

Returns awserr.Error for service API and SDK errors. Use runtime type assertions with awserr.Error's Code and Message methods to get detailed information about the error.

See the AWS API reference guide for AWS Key Management Service's API operation GenerateDataKey for usage and error information.

Returned Error Codes:

  • ErrCodeNotFoundException "NotFoundException" The request was rejected because the specified entity or resource could not be found.

  • ErrCodeDisabledException "DisabledException" The request was rejected because the specified CMK is not enabled.

  • ErrCodeKeyUnavailableException "KeyUnavailableException" The request was rejected because the specified CMK was not available. The request can be retried.

  • ErrCodeDependencyTimeoutException "DependencyTimeoutException" The system timed out while trying to fulfill the request. The request can be retried.

  • ErrCodeInvalidKeyUsageException "InvalidKeyUsageException" The request was rejected because the specified KeySpec value is not valid.

  • ErrCodeInvalidGrantTokenException "InvalidGrantTokenException" The request was rejected because the specified grant token is not valid.

  • ErrCodeInternalException "KMSInternalException" The request was rejected because an internal exception occurred. The request can be retried.

  • ErrCodeInvalidStateException "KMSInvalidStateException" The request was rejected because the state of the specified resource is not valid for this request.

For more information about how key state affects the use of a CMK, see How Key State Affects Use of a Customer Master Key (http://docs.aws.amazon.com/kms/latest/developerguide/key-state.html) in the AWS Key Management Service Developer Guide.

See also, https://docs.aws.amazon.com/goto/WebAPI/kms-2014-11-01/GenerateDataKey

Example

KMS GenerateDataKey shared00

To generate a data key

The following example generates a 256-bit symmetric data encryption key (data key) in two formats. One is the unencrypted (plainext) data key, and the other is the data key encrypted with the specified customer master key (CMK).

{ svc := kms.New(session.New()) input := &kms.GenerateDataKeyInput{ KeyId: aws.String("alias/ExampleAlias"), KeySpec: aws.String("AES_256"), } result, err := svc.GenerateDataKey(input) if err != nil { if aerr, ok := err.(awserr.Error); ok { switch aerr.Code() { case kms.ErrCodeNotFoundException: fmt.Println(kms.ErrCodeNotFoundException, aerr.Error()) case kms.ErrCodeDisabledException: fmt.Println(kms.ErrCodeDisabledException, aerr.Error()) case kms.ErrCodeKeyUnavailableException: fmt.Println(kms.ErrCodeKeyUnavailableException, aerr.Error()) case kms.ErrCodeDependencyTimeoutException: fmt.Println(kms.ErrCodeDependencyTimeoutException, aerr.Error()) case kms.ErrCodeInvalidKeyUsageException: fmt.Println(kms.ErrCodeInvalidKeyUsageException, aerr.Error()) case kms.ErrCodeInvalidGrantTokenException: fmt.Println(kms.ErrCodeInvalidGrantTokenException, aerr.Error()) case kms.ErrCodeInternalException: fmt.Println(kms.ErrCodeInternalException, aerr.Error()) case kms.ErrCodeInvalidStateException: fmt.Println(kms.ErrCodeInvalidStateException, aerr.Error()) default: fmt.Println(aerr.Error()) } } else { fmt.Println(err.Error()) } return } fmt.Println(result) }

GenerateDataKeyRequest

func (c *KMS) GenerateDataKeyRequest(input *GenerateDataKeyInput) (req *request.Request, output *GenerateDataKeyOutput)

GenerateDataKeyRequest generates a "aws/request.Request" representing the client's request for the GenerateDataKey operation. The "output" return value will be populated with the request's response once the request completes successfully.

Use "Send" method on the returned Request to send the API call to the service. the "output" return value is not valid until after Send returns without error.

See GenerateDataKey for more information on using the GenerateDataKey API call, and error handling.

This method is useful when you want to inject custom logic or configuration into the SDK's request lifecycle. Such as custom headers, or retry logic.

// Example sending a request using the GenerateDataKeyRequest method. req, resp := client.GenerateDataKeyRequest(params) err := req.Send() if err == nil { // resp is now filled fmt.Println(resp) }

See also, https://docs.aws.amazon.com/goto/WebAPI/kms-2014-11-01/GenerateDataKey

GenerateDataKeyWithContext

func (c *KMS) GenerateDataKeyWithContext(ctx aws.Context, input *GenerateDataKeyInput, opts ...request.Option) (*GenerateDataKeyOutput, error)

GenerateDataKeyWithContext is the same as GenerateDataKey with the addition of the ability to pass a context and additional request options.

See GenerateDataKey for details on how to use this API operation.

The context must be non-nil and will be used for request cancellation. If the context is nil a panic will occur. In the future the SDK may create sub-contexts for http.Requests. See https://golang.org/pkg/context/ for more information on using Contexts.

See Also

For more information about using this API, see AWS API Documentation.

GenerateDataKeyWithoutPlaintext

func (c *KMS) GenerateDataKeyWithoutPlaintext(input *GenerateDataKeyWithoutPlaintextInput) (*GenerateDataKeyWithoutPlaintextOutput, error)

GenerateDataKeyWithoutPlaintext API operation for AWS Key Management Service.

Returns a data encryption key encrypted under a customer master key (CMK). This operation is identical to GenerateDataKey but returns only the encrypted copy of the data key.

To perform this operation on a CMK in a different AWS account, specify the key ARN or alias ARN in the value of the KeyId parameter.

This operation is useful in a system that has multiple components with different degrees of trust. For example, consider a system that stores encrypted data in containers. Each container stores the encrypted data and an encrypted copy of the data key. One component of the system, called the control plane, creates new containers. When it creates a new container, it uses this operation (GenerateDataKeyWithoutPlaintext) to get an encrypted data key and then stores it in the container. Later, a different component of the system, called the data plane, puts encrypted data into the containers. To do this, it passes the encrypted data key to the Decrypt operation, then uses the returned plaintext data key to encrypt data, and finally stores the encrypted data in the container. In this system, the control plane never sees the plaintext data key.

The result of this operation varies with the key state of the CMK. For details, see How Key State Affects Use of a Customer Master Key (https://docs.aws.amazon.com/kms/latest/developerguide/key-state.html) in the AWS Key Management Service Developer Guide.

Returns awserr.Error for service API and SDK errors. Use runtime type assertions with awserr.Error's Code and Message methods to get detailed information about the error.

See the AWS API reference guide for AWS Key Management Service's API operation GenerateDataKeyWithoutPlaintext for usage and error information.

Returned Error Codes:

  • ErrCodeNotFoundException "NotFoundException" The request was rejected because the specified entity or resource could not be found.

  • ErrCodeDisabledException "DisabledException" The request was rejected because the specified CMK is not enabled.

  • ErrCodeKeyUnavailableException "KeyUnavailableException" The request was rejected because the specified CMK was not available. The request can be retried.

  • ErrCodeDependencyTimeoutException "DependencyTimeoutException" The system timed out while trying to fulfill the request. The request can be retried.

  • ErrCodeInvalidKeyUsageException "InvalidKeyUsageException" The request was rejected because the specified KeySpec value is not valid.

  • ErrCodeInvalidGrantTokenException "InvalidGrantTokenException" The request was rejected because the specified grant token is not valid.

  • ErrCodeInternalException "KMSInternalException" The request was rejected because an internal exception occurred. The request can be retried.

  • ErrCodeInvalidStateException "KMSInvalidStateException" The request was rejected because the state of the specified resource is not valid for this request.

For more information about how key state affects the use of a CMK, see How Key State Affects Use of a Customer Master Key (http://docs.aws.amazon.com/kms/latest/developerguide/key-state.html) in the AWS Key Management Service Developer Guide.

See also, https://docs.aws.amazon.com/goto/WebAPI/kms-2014-11-01/GenerateDataKeyWithoutPlaintext

Example

KMS GenerateDataKeyWithoutPlaintext shared00

To generate an encrypted data key

The following example generates an encrypted copy of a 256-bit symmetric data encryption key (data key). The data key is encrypted with the specified customer master key (CMK).

{ svc := kms.New(session.New()) input := &kms.GenerateDataKeyWithoutPlaintextInput{ KeyId: aws.String("alias/ExampleAlias"), KeySpec: aws.String("AES_256"), } result, err := svc.GenerateDataKeyWithoutPlaintext(input) if err != nil { if aerr, ok := err.(awserr.Error); ok { switch aerr.Code() { case kms.ErrCodeNotFoundException: fmt.Println(kms.ErrCodeNotFoundException, aerr.Error()) case kms.ErrCodeDisabledException: fmt.Println(kms.ErrCodeDisabledException, aerr.Error()) case kms.ErrCodeKeyUnavailableException: fmt.Println(kms.ErrCodeKeyUnavailableException, aerr.Error()) case kms.ErrCodeDependencyTimeoutException: fmt.Println(kms.ErrCodeDependencyTimeoutException, aerr.Error()) case kms.ErrCodeInvalidKeyUsageException: fmt.Println(kms.ErrCodeInvalidKeyUsageException, aerr.Error()) case kms.ErrCodeInvalidGrantTokenException: fmt.Println(kms.ErrCodeInvalidGrantTokenException, aerr.Error()) case kms.ErrCodeInternalException: fmt.Println(kms.ErrCodeInternalException, aerr.Error()) case kms.ErrCodeInvalidStateException: fmt.Println(kms.ErrCodeInvalidStateException, aerr.Error()) default: fmt.Println(aerr.Error()) } } else { fmt.Println(err.Error()) } return } fmt.Println(result) }

GenerateDataKeyWithoutPlaintextRequest

func (c *KMS) GenerateDataKeyWithoutPlaintextRequest(input *GenerateDataKeyWithoutPlaintextInput) (req *request.Request, output *GenerateDataKeyWithoutPlaintextOutput)

GenerateDataKeyWithoutPlaintextRequest generates a "aws/request.Request" representing the client's request for the GenerateDataKeyWithoutPlaintext operation. The "output" return value will be populated with the request's response once the request completes successfully.

Use "Send" method on the returned Request to send the API call to the service. the "output" return value is not valid until after Send returns without error.

See GenerateDataKeyWithoutPlaintext for more information on using the GenerateDataKeyWithoutPlaintext API call, and error handling.

This method is useful when you want to inject custom logic or configuration into the SDK's request lifecycle. Such as custom headers, or retry logic.

// Example sending a request using the GenerateDataKeyWithoutPlaintextRequest method. req, resp := client.GenerateDataKeyWithoutPlaintextRequest(params) err := req.Send() if err == nil { // resp is now filled fmt.Println(resp) }

See also, https://docs.aws.amazon.com/goto/WebAPI/kms-2014-11-01/GenerateDataKeyWithoutPlaintext

GenerateDataKeyWithoutPlaintextWithContext

func (c *KMS) GenerateDataKeyWithoutPlaintextWithContext(ctx aws.Context, input *GenerateDataKeyWithoutPlaintextInput, opts ...request.Option) (*GenerateDataKeyWithoutPlaintextOutput, error)

GenerateDataKeyWithoutPlaintextWithContext is the same as GenerateDataKeyWithoutPlaintext with the addition of the ability to pass a context and additional request options.

See GenerateDataKeyWithoutPlaintext for details on how to use this API operation.

The context must be non-nil and will be used for request cancellation. If the context is nil a panic will occur. In the future the SDK may create sub-contexts for http.Requests. See https://golang.org/pkg/context/ for more information on using Contexts.

See Also

For more information about using this API, see AWS API Documentation.

GenerateRandom

func (c *KMS) GenerateRandom(input *GenerateRandomInput) (*GenerateRandomOutput, error)

GenerateRandom API operation for AWS Key Management Service.

Returns a random byte string that is cryptographically secure.

By default, the random byte string is generated in AWS KMS. To generate the byte string in the AWS CloudHSM cluster that is associated with a custom key store (https://docs.aws.amazon.com/kms/latest/developerguide/key-store-overview.html), specify the custom key store ID.

For more information about entropy and random number generation, see the AWS Key Management Service Cryptographic Details (https://d0.awsstatic.com/whitepapers/KMS-Cryptographic-Details.pdf) whitepaper.

Returns awserr.Error for service API and SDK errors. Use runtime type assertions with awserr.Error's Code and Message methods to get detailed information about the error.

See the AWS API reference guide for AWS Key Management Service's API operation GenerateRandom for usage and error information.

Returned Error Codes:

  • ErrCodeDependencyTimeoutException "DependencyTimeoutException" The system timed out while trying to fulfill the request. The request can be retried.

  • ErrCodeInternalException "KMSInternalException" The request was rejected because an internal exception occurred. The request can be retried.

  • ErrCodeCustomKeyStoreNotFoundException "CustomKeyStoreNotFoundException" The request was rejected because AWS KMS cannot find a custom key store with the specified key store name or ID.

  • ErrCodeCustomKeyStoreInvalidStateException "CustomKeyStoreInvalidStateException" The request was rejected because of the ConnectionState of the custom key store. To get the ConnectionState of a custom key store, use the DescribeCustomKeyStores operation.

This exception is thrown under the following conditions:
  • You requested the CreateKey or GenerateRandom operation in a custom key store that is not connected. These operations are valid only when the custom key store ConnectionState is CONNECTED.

  • You requested the UpdateCustomKeyStore or DeleteCustomKeyStore operation on a custom key store that is not disconnected. This operation is valid only when the custom key store ConnectionState is DISCONNECTED.

  • You requested the ConnectCustomKeyStore operation on a custom key store with a ConnectionState of DISCONNECTING or FAILED. This operation is valid for all other ConnectionState values.

See also, https://docs.aws.amazon.com/goto/WebAPI/kms-2014-11-01/GenerateRandom

Example

KMS GenerateRandom shared00

To generate random data

The following example uses AWS KMS to generate 32 bytes of random data.

{ svc := kms.New(session.New()) input := &kms.GenerateRandomInput{ NumberOfBytes: aws.Int64(32), } result, err := svc.GenerateRandom(input) if err != nil { if aerr, ok := err.(awserr.Error); ok { switch aerr.Code() { case kms.ErrCodeDependencyTimeoutException: fmt.Println(kms.ErrCodeDependencyTimeoutException, aerr.Error()) case kms.ErrCodeInternalException: fmt.Println(kms.ErrCodeInternalException, aerr.Error()) case kms.ErrCodeCustomKeyStoreNotFoundException: fmt.Println(kms.ErrCodeCustomKeyStoreNotFoundException, aerr.Error()) case kms.ErrCodeCustomKeyStoreInvalidStateException: fmt.Println(kms.ErrCodeCustomKeyStoreInvalidStateException, aerr.Error()) default: fmt.Println(aerr.Error()) } } else { fmt.Println(err.Error()) } return } fmt.Println(result) }

GenerateRandomRequest

func (c *KMS) GenerateRandomRequest(input *GenerateRandomInput) (req *request.Request, output *GenerateRandomOutput)

GenerateRandomRequest generates a "aws/request.Request" representing the client's request for the GenerateRandom operation. The "output" return value will be populated with the request's response once the request completes successfully.

Use "Send" method on the returned Request to send the API call to the service. the "output" return value is not valid until after Send returns without error.

See GenerateRandom for more information on using the GenerateRandom API call, and error handling.

This method is useful when you want to inject custom logic or configuration into the SDK's request lifecycle. Such as custom headers, or retry logic.

// Example sending a request using the GenerateRandomRequest method. req, resp := client.GenerateRandomRequest(params) err := req.Send() if err == nil { // resp is now filled fmt.Println(resp) }

See also, https://docs.aws.amazon.com/goto/WebAPI/kms-2014-11-01/GenerateRandom

GenerateRandomWithContext

func (c *KMS) GenerateRandomWithContext(ctx aws.Context, input *GenerateRandomInput, opts ...request.Option) (*GenerateRandomOutput, error)

GenerateRandomWithContext is the same as GenerateRandom with the addition of the ability to pass a context and additional request options.

See GenerateRandom for details on how to use this API operation.

The context must be non-nil and will be used for request cancellation. If the context is nil a panic will occur. In the future the SDK may create sub-contexts for http.Requests. See https://golang.org/pkg/context/ for more information on using Contexts.

See Also

For more information about using this API, see AWS API Documentation.

GetKeyPolicy

func (c *KMS) GetKeyPolicy(input *GetKeyPolicyInput) (*GetKeyPolicyOutput, error)

GetKeyPolicy API operation for AWS Key Management Service.

Gets a key policy attached to the specified customer master key (CMK). You cannot perform this operation on a CMK in a different AWS account.

Returns awserr.Error for service API and SDK errors. Use runtime type assertions with awserr.Error's Code and Message methods to get detailed information about the error.

See the AWS API reference guide for AWS Key Management Service's API operation GetKeyPolicy for usage and error information.

Returned Error Codes:

  • ErrCodeNotFoundException "NotFoundException" The request was rejected because the specified entity or resource could not be found.

  • ErrCodeInvalidArnException "InvalidArnException" The request was rejected because a specified ARN was not valid.

  • ErrCodeDependencyTimeoutException "DependencyTimeoutException" The system timed out while trying to fulfill the request. The request can be retried.

  • ErrCodeInternalException "KMSInternalException" The request was rejected because an internal exception occurred. The request can be retried.

  • ErrCodeInvalidStateException "KMSInvalidStateException" The request was rejected because the state of the specified resource is not valid for this request.

For more information about how key state affects the use of a CMK, see How Key State Affects Use of a Customer Master Key (http://docs.aws.amazon.com/kms/latest/developerguide/key-state.html) in the AWS Key Management Service Developer Guide.

See also, https://docs.aws.amazon.com/goto/WebAPI/kms-2014-11-01/GetKeyPolicy

Example

KMS GetKeyPolicy shared00

To retrieve a key policy

The following example retrieves the key policy for the specified customer master key (CMK).

{ svc := kms.New(session.New()) input := &kms.GetKeyPolicyInput{ KeyId: aws.String("1234abcd-12ab-34cd-56ef-1234567890ab"), PolicyName: aws.String("default"), } result, err := svc.GetKeyPolicy(input) if err != nil { if aerr, ok := err.(awserr.Error); ok { switch aerr.Code() { case kms.ErrCodeNotFoundException: fmt.Println(kms.ErrCodeNotFoundException, aerr.Error()) case kms.ErrCodeInvalidArnException: fmt.Println(kms.ErrCodeInvalidArnException, aerr.Error()) case kms.ErrCodeDependencyTimeoutException: fmt.Println(kms.ErrCodeDependencyTimeoutException, aerr.Error()) case kms.ErrCodeInternalException: fmt.Println(kms.ErrCodeInternalException, aerr.Error()) case kms.ErrCodeInvalidStateException: fmt.Println(kms.ErrCodeInvalidStateException, aerr.Error()) default: fmt.Println(aerr.Error()) } } else { fmt.Println(err.Error()) } return } fmt.Println(result) }

GetKeyPolicyRequest

func (c *KMS) GetKeyPolicyRequest(input *GetKeyPolicyInput) (req *request.Request, output *GetKeyPolicyOutput)

GetKeyPolicyRequest generates a "aws/request.Request" representing the client's request for the GetKeyPolicy operation. The "output" return value will be populated with the request's response once the request completes successfully.

Use "Send" method on the returned Request to send the API call to the service. the "output" return value is not valid until after Send returns without error.

See GetKeyPolicy for more information on using the GetKeyPolicy API call, and error handling.

This method is useful when you want to inject custom logic or configuration into the SDK's request lifecycle. Such as custom headers, or retry logic.

// Example sending a request using the GetKeyPolicyRequest method. req, resp := client.GetKeyPolicyRequest(params) err := req.Send() if err == nil { // resp is now filled fmt.Println(resp) }

See also, https://docs.aws.amazon.com/goto/WebAPI/kms-2014-11-01/GetKeyPolicy

GetKeyPolicyWithContext

func (c *KMS) GetKeyPolicyWithContext(ctx aws.Context, input *GetKeyPolicyInput, opts ...request.Option) (*GetKeyPolicyOutput, error)

GetKeyPolicyWithContext is the same as GetKeyPolicy with the addition of the ability to pass a context and additional request options.

See GetKeyPolicy for details on how to use this API operation.

The context must be non-nil and will be used for request cancellation. If the context is nil a panic will occur. In the future the SDK may create sub-contexts for http.Requests. See https://golang.org/pkg/context/ for more information on using Contexts.

See Also

For more information about using this API, see AWS API Documentation.

GetKeyRotationStatus

func (c *KMS) GetKeyRotationStatus(input *GetKeyRotationStatusInput) (*GetKeyRotationStatusOutput, error)

GetKeyRotationStatus API operation for AWS Key Management Service.

Gets a Boolean value that indicates whether automatic rotation of the key material (https://docs.aws.amazon.com/kms/latest/developerguide/rotate-keys.html) is enabled for the specified customer master key (CMK).

The result of this operation varies with the key state of the CMK. For details, see How Key State Affects Use of a Customer Master Key (https://docs.aws.amazon.com/kms/latest/developerguide/key-state.html) in the AWS Key Management Service Developer Guide.

  • Disabled: The key rotation status does not change when you disable a CMK. However, while the CMK is disabled, AWS KMS does not rotate the backing key.

  • Pending deletion: While a CMK is pending deletion, its key rotation status is false and AWS KMS does not rotate the backing key. If you cancel the deletion, the original key rotation status is restored.

To perform this operation on a CMK in a different AWS account, specify the key ARN in the value of the KeyId parameter.

Returns awserr.Error for service API and SDK errors. Use runtime type assertions with awserr.Error's Code and Message methods to get detailed information about the error.

See the AWS API reference guide for AWS Key Management Service's API operation GetKeyRotationStatus for usage and error information.

Returned Error Codes:

  • ErrCodeNotFoundException "NotFoundException" The request was rejected because the specified entity or resource could not be found.

  • ErrCodeInvalidArnException "InvalidArnException" The request was rejected because a specified ARN was not valid.

  • ErrCodeDependencyTimeoutException "DependencyTimeoutException" The system timed out while trying to fulfill the request. The request can be retried.

  • ErrCodeInternalException "KMSInternalException" The request was rejected because an internal exception occurred. The request can be retried.

  • ErrCodeInvalidStateException "KMSInvalidStateException" The request was rejected because the state of the specified resource is not valid for this request.

For more information about how key state affects the use of a CMK, see How Key State Affects Use of a Customer Master Key (http://docs.aws.amazon.com/kms/latest/developerguide/key-state.html) in the AWS Key Management Service Developer Guide.
  • ErrCodeUnsupportedOperationException "UnsupportedOperationException" The request was rejected because a specified parameter is not supported or a specified resource is not valid for this operation.

See also, https://docs.aws.amazon.com/goto/WebAPI/kms-2014-11-01/GetKeyRotationStatus

Example

KMS GetKeyRotationStatus shared00

To retrieve the rotation status for a customer master key (CMK)

The following example retrieves the status of automatic annual rotation of the key material for the specified CMK.

{ svc := kms.New(session.New()) input := &kms.GetKeyRotationStatusInput{ KeyId: aws.String("1234abcd-12ab-34cd-56ef-1234567890ab"), } result, err := svc.GetKeyRotationStatus(input) if err != nil { if aerr, ok := err.(awserr.Error); ok { switch aerr.Code() { case kms.ErrCodeNotFoundException: fmt.Println(kms.ErrCodeNotFoundException, aerr.Error()) case kms.ErrCodeInvalidArnException: fmt.Println(kms.ErrCodeInvalidArnException, aerr.Error()) case kms.ErrCodeDependencyTimeoutException: fmt.Println(kms.ErrCodeDependencyTimeoutException, aerr.Error()) case kms.ErrCodeInternalException: fmt.Println(kms.ErrCodeInternalException, aerr.Error()) case kms.ErrCodeInvalidStateException: fmt.Println(kms.ErrCodeInvalidStateException, aerr.Error()) case kms.ErrCodeUnsupportedOperationException: fmt.Println(kms.ErrCodeUnsupportedOperationException, aerr.Error()) default: fmt.Println(aerr.Error()) } } else { fmt.Println(err.Error()) } return } fmt.Println(result) }

GetKeyRotationStatusRequest

func (c *KMS) GetKeyRotationStatusRequest(input *GetKeyRotationStatusInput) (req *request.Request, output *GetKeyRotationStatusOutput)

GetKeyRotationStatusRequest generates a "aws/request.Request" representing the client's request for the GetKeyRotationStatus operation. The "output" return value will be populated with the request's response once the request completes successfully.

Use "Send" method on the returned Request to send the API call to the service. the "output" return value is not valid until after Send returns without error.

See GetKeyRotationStatus for more information on using the GetKeyRotationStatus API call, and error handling.

This method is useful when you want to inject custom logic or configuration into the SDK's request lifecycle. Such as custom headers, or retry logic.

// Example sending a request using the GetKeyRotationStatusRequest method. req, resp := client.GetKeyRotationStatusRequest(params) err := req.Send() if err == nil { // resp is now filled fmt.Println(resp) }

See also, https://docs.aws.amazon.com/goto/WebAPI/kms-2014-11-01/GetKeyRotationStatus

GetKeyRotationStatusWithContext

func (c *KMS) GetKeyRotationStatusWithContext(ctx aws.Context, input *GetKeyRotationStatusInput, opts ...request.Option) (*GetKeyRotationStatusOutput, error)

GetKeyRotationStatusWithContext is the same as GetKeyRotationStatus with the addition of the ability to pass a context and additional request options.

See GetKeyRotationStatus for details on how to use this API operation.

The context must be non-nil and will be used for request cancellation. If the context is nil a panic will occur. In the future the SDK may create sub-contexts for http.Requests. See https://golang.org/pkg/context/ for more information on using Contexts.

See Also

For more information about using this API, see AWS API Documentation.

GetParametersForImport

func (c *KMS) GetParametersForImport(input *GetParametersForImportInput) (*GetParametersForImportOutput, error)

GetParametersForImport API operation for AWS Key Management Service.

Returns the items you need in order to import key material into AWS KMS from your existing key management infrastructure. For more information about importing key material into AWS KMS, see Importing Key Material (https://docs.aws.amazon.com/kms/latest/developerguide/importing-keys.html) in the AWS Key Management Service Developer Guide.

You must specify the key ID of the customer master key (CMK) into which you will import key material. This CMK's Origin must be EXTERNAL. You must also specify the wrapping algorithm and type of wrapping key (public key) that you will use to encrypt the key material. You cannot perform this operation on a CMK in a different AWS account.

This operation returns a public key and an import token. Use the public key to encrypt the key material. Store the import token to send with a subsequent ImportKeyMaterial request. The public key and import token from the same response must be used together. These items are valid for 24 hours. When they expire, they cannot be used for a subsequent ImportKeyMaterial request. To get new ones, send another GetParametersForImport request.

The result of this operation varies with the key state of the CMK. For details, see How Key State Affects Use of a Customer Master Key (https://docs.aws.amazon.com/kms/latest/developerguide/key-state.html) in the AWS Key Management Service Developer Guide.

Returns awserr.Error for service API and SDK errors. Use runtime type assertions with awserr.Error's Code and Message methods to get detailed information about the error.

See the AWS API reference guide for AWS Key Management Service's API operation GetParametersForImport for usage and error information.

Returned Error Codes:

  • ErrCodeInvalidArnException "InvalidArnException" The request was rejected because a specified ARN was not valid.

  • ErrCodeUnsupportedOperationException "UnsupportedOperationException" The request was rejected because a specified parameter is not supported or a specified resource is not valid for this operation.

  • ErrCodeDependencyTimeoutException "DependencyTimeoutException" The system timed out while trying to fulfill the request. The request can be retried.

  • ErrCodeNotFoundException "NotFoundException" The request was rejected because the specified entity or resource could not be found.

  • ErrCodeInternalException "KMSInternalException" The request was rejected because an internal exception occurred. The request can be retried.

  • ErrCodeInvalidStateException "KMSInvalidStateException" The request was rejected because the state of the specified resource is not valid for this request.

For more information about how key state affects the use of a CMK, see How Key State Affects Use of a Customer Master Key (http://docs.aws.amazon.com/kms/latest/developerguide/key-state.html) in the AWS Key Management Service Developer Guide.

See also, https://docs.aws.amazon.com/goto/WebAPI/kms-2014-11-01/GetParametersForImport

Example

KMS GetParametersForImport shared00

To retrieve the public key and import token for a customer master key (CMK)

The following example retrieves the public key and import token for the specified CMK.

{ svc := kms.New(session.New()) input := &kms.GetParametersForImportInput{ KeyId: aws.String("1234abcd-12ab-34cd-56ef-1234567890ab"), WrappingAlgorithm: aws.String("RSAES_OAEP_SHA_1"), WrappingKeySpec: aws.String("RSA_2048"), } result, err := svc.GetParametersForImport(input) if err != nil { if aerr, ok := err.(awserr.Error); ok { switch aerr.Code() { case kms.ErrCodeInvalidArnException: fmt.Println(kms.ErrCodeInvalidArnException, aerr.Error()) case kms.ErrCodeUnsupportedOperationException: fmt.Println(kms.ErrCodeUnsupportedOperationException, aerr.Error()) case kms.ErrCodeDependencyTimeoutException: fmt.Println(kms.ErrCodeDependencyTimeoutException, aerr.Error()) case kms.ErrCodeNotFoundException: fmt.Println(kms.ErrCodeNotFoundException, aerr.Error()) case kms.ErrCodeInternalException: fmt.Println(kms.ErrCodeInternalException, aerr.Error()) case kms.ErrCodeInvalidStateException: fmt.Println(kms.ErrCodeInvalidStateException, aerr.Error()) default: fmt.Println(aerr.Error()) } } else { fmt.Println(err.Error()) } return } fmt.Println(result) }

GetParametersForImportRequest

func (c *KMS) GetParametersForImportRequest(input *GetParametersForImportInput) (req *request.Request, output *GetParametersForImportOutput)

GetParametersForImportRequest generates a "aws/request.Request" representing the client's request for the GetParametersForImport operation. The "output" return value will be populated with the request's response once the request completes successfully.

Use "Send" method on the returned Request to send the API call to the service. the "output" return value is not valid until after Send returns without error.

See GetParametersForImport for more information on using the GetParametersForImport API call, and error handling.

This method is useful when you want to inject custom logic or configuration into the SDK's request lifecycle. Such as custom headers, or retry logic.

// Example sending a request using the GetParametersForImportRequest method. req, resp := client.GetParametersForImportRequest(params) err := req.Send() if err == nil { // resp is now filled fmt.Println(resp) }

See also, https://docs.aws.amazon.com/goto/WebAPI/kms-2014-11-01/GetParametersForImport

GetParametersForImportWithContext

func (c *KMS) GetParametersForImportWithContext(ctx aws.Context, input *GetParametersForImportInput, opts ...request.Option) (*GetParametersForImportOutput, error)

GetParametersForImportWithContext is the same as GetParametersForImport with the addition of the ability to pass a context and additional request options.

See GetParametersForImport for details on how to use this API operation.

The context must be non-nil and will be used for request cancellation. If the context is nil a panic will occur. In the future the SDK may create sub-contexts for http.Requests. See https://golang.org/pkg/context/ for more information on using Contexts.

See Also

For more information about using this API, see AWS API Documentation.

ImportKeyMaterial

func (c *KMS) ImportKeyMaterial(input *ImportKeyMaterialInput) (*ImportKeyMaterialOutput, error)

ImportKeyMaterial API operation for AWS Key Management Service.

Imports key material into an existing AWS KMS customer master key (CMK) that was created without key material. You cannot perform this operation on a CMK in a different AWS account. For more information about creating CMKs with no key material and then importing key material, see Importing Key Material (https://docs.aws.amazon.com/kms/latest/developerguide/importing-keys.html) in the AWS Key Management Service Developer Guide.

Before using this operation, call GetParametersForImport. Its response includes a public key and an import token. Use the public key to encrypt the key material. Then, submit the import token from the same GetParametersForImport response.

When calling this operation, you must specify the following values:

  • The key ID or key ARN of a CMK with no key material. Its Origin must be EXTERNAL.

To create a CMK with no key material, call CreateKey and set the value of

its Origin parameter to EXTERNAL. To get the Origin of a CMK, call DescribeKey.)
  • The encrypted key material. To get the public key to encrypt the key material, call GetParametersForImport.

  • The import token that GetParametersForImport returned. This token and the public key used to encrypt the key material must have come from the same response.

  • Whether the key material expires and if so, when. If you set an expiration date, you can change it only by reimporting the same key material and specifying a new expiration date. If the key material expires, AWS KMS deletes the key material and the CMK becomes unusable. To use the CMK again, you must reimport the same key material.

When this operation is successful, the key state of the CMK changes from PendingImport to Enabled, and you can use the CMK. After you successfully import key material into a CMK, you can reimport the same key material into that CMK, but you cannot import different key material.

The result of this operation varies with the key state of the CMK. For details, see How Key State Affects Use of a Customer Master Key (https://docs.aws.amazon.com/kms/latest/developerguide/key-state.html) in the AWS Key Management Service Developer Guide.

Returns awserr.Error for service API and SDK errors. Use runtime type assertions with awserr.Error's Code and Message methods to get detailed information about the error.

See the AWS API reference guide for AWS Key Management Service's API operation ImportKeyMaterial for usage and error information.

Returned Error Codes:

  • ErrCodeInvalidArnException "InvalidArnException" The request was rejected because a specified ARN was not valid.

  • ErrCodeUnsupportedOperationException "UnsupportedOperationException" The request was rejected because a specified parameter is not supported or a specified resource is not valid for this operation.

  • ErrCodeDependencyTimeoutException "DependencyTimeoutException" The system timed out while trying to fulfill the request. The request can be retried.

  • ErrCodeNotFoundException "NotFoundException" The request was rejected because the specified entity or resource could not be found.

  • ErrCodeInternalException "KMSInternalException" The request was rejected because an internal exception occurred. The request can be retried.

  • ErrCodeInvalidStateException "KMSInvalidStateException" The request was rejected because the state of the specified resource is not valid for this request.

For more information about how key state affects the use of a CMK, see How Key State Affects Use of a Customer Master Key (http://docs.aws.amazon.com/kms/latest/developerguide/key-state.html) in the AWS Key Management Service Developer Guide.
  • ErrCodeInvalidCiphertextException "InvalidCiphertextException" The request was rejected because the specified ciphertext, or additional authenticated data incorporated into the ciphertext, such as the encryption context, is corrupted, missing, or otherwise invalid.

  • ErrCodeIncorrectKeyMaterialException "IncorrectKeyMaterialException" The request was rejected because the provided key material is invalid or is not the same key material that was previously imported into this customer master key (CMK).

  • ErrCodeExpiredImportTokenException "ExpiredImportTokenException" The request was rejected because the provided import token is expired. Use GetParametersForImport to get a new import token and public key, use the new public key to encrypt the key material, and then try the request again.

  • ErrCodeInvalidImportTokenException "InvalidImportTokenException" The request was rejected because the provided import token is invalid or is associated with a different customer master key (CMK).

See also, https://docs.aws.amazon.com/goto/WebAPI/kms-2014-11-01/ImportKeyMaterial

Example

KMS ImportKeyMaterial shared00

To import key material into a customer master key (CMK)

The following example imports key material into the specified CMK.

{ svc := kms.New(session.New()) input := &kms.ImportKeyMaterialInput{ EncryptedKeyMaterial: []byte("<binary data>"), ExpirationModel: aws.String("KEY_MATERIAL_DOES_NOT_EXPIRE"), ImportToken: []byte("<binary data>"), KeyId: aws.String("1234abcd-12ab-34cd-56ef-1234567890ab"), } result, err := svc.ImportKeyMaterial(input) if err != nil { if aerr, ok := err.(awserr.Error); ok { switch aerr.Code() { case kms.ErrCodeInvalidArnException: fmt.Println(kms.ErrCodeInvalidArnException, aerr.Error()) case kms.ErrCodeUnsupportedOperationException: fmt.Println(kms.ErrCodeUnsupportedOperationException, aerr.Error()) case kms.ErrCodeDependencyTimeoutException: fmt.Println(kms.ErrCodeDependencyTimeoutException, aerr.Error()) case kms.ErrCodeNotFoundException: fmt.Println(kms.ErrCodeNotFoundException, aerr.Error()) case kms.ErrCodeInternalException: fmt.Println(kms.ErrCodeInternalException, aerr.Error()) case kms.ErrCodeInvalidStateException: fmt.Println(kms.ErrCodeInvalidStateException, aerr.Error()) case kms.ErrCodeInvalidCiphertextException: fmt.Println(kms.ErrCodeInvalidCiphertextException, aerr.Error()) case kms.ErrCodeIncorrectKeyMaterialException: fmt.Println(kms.ErrCodeIncorrectKeyMaterialException, aerr.Error()) case kms.ErrCodeExpiredImportTokenException: fmt.Println(kms.ErrCodeExpiredImportTokenException, aerr.Error()) case kms.ErrCodeInvalidImportTokenException: fmt.Println(kms.ErrCodeInvalidImportTokenException, aerr.Error()) default: fmt.Println(aerr.Error()) } } else { fmt.Println(err.Error()) } return } fmt.Println(result) }

ImportKeyMaterialRequest

func (c *KMS) ImportKeyMaterialRequest(input *ImportKeyMaterialInput) (req *request.Request, output *ImportKeyMaterialOutput)

ImportKeyMaterialRequest generates a "aws/request.Request" representing the client's request for the ImportKeyMaterial operation. The "output" return value will be populated with the request's response once the request completes successfully.

Use "Send" method on the returned Request to send the API call to the service. the "output" return value is not valid until after Send returns without error.

See ImportKeyMaterial for more information on using the ImportKeyMaterial API call, and error handling.

This method is useful when you want to inject custom logic or configuration into the SDK's request lifecycle. Such as custom headers, or retry logic.

// Example sending a request using the ImportKeyMaterialRequest method. req, resp := client.ImportKeyMaterialRequest(params) err := req.Send() if err == nil { // resp is now filled fmt.Println(resp) }

See also, https://docs.aws.amazon.com/goto/WebAPI/kms-2014-11-01/ImportKeyMaterial

ImportKeyMaterialWithContext

func (c *KMS) ImportKeyMaterialWithContext(ctx aws.Context, input *ImportKeyMaterialInput, opts ...request.Option) (*ImportKeyMaterialOutput, error)

ImportKeyMaterialWithContext is the same as ImportKeyMaterial with the addition of the ability to pass a context and additional request options.

See ImportKeyMaterial for details on how to use this API operation.

The context must be non-nil and will be used for request cancellation. If the context is nil a panic will occur. In the future the SDK may create sub-contexts for http.Requests. See https://golang.org/pkg/context/ for more information on using Contexts.

See Also

For more information about using this API, see AWS API Documentation.

ListAliases

func (c *KMS) ListAliases(input *ListAliasesInput) (*ListAliasesOutput, error)

ListAliases API operation for AWS Key Management Service.

Gets a list of all aliases in the caller's AWS account and region. You cannot list aliases in other accounts. For more information about aliases, see CreateAlias.

By default, the ListAliases command returns all aliases in the account and region. To get only the aliases that point to a particular customer master key (CMK), use the KeyId parameter.

The ListAliases response might include several aliases have no TargetKeyId field. These are predefined aliases that AWS has created but has not yet associated with a CMK. Aliases that AWS creates in your account, including predefined aliases, do not count against your AWS KMS aliases limit (https://docs.aws.amazon.com/kms/latest/developerguide/limits.html#aliases-limit).

Returns awserr.Error for service API and SDK errors. Use runtime type assertions with awserr.Error's Code and Message methods to get detailed information about the error.

See the AWS API reference guide for AWS Key Management Service's API operation ListAliases for usage and error information.

Returned Error Codes:

  • ErrCodeDependencyTimeoutException "DependencyTimeoutException" The system timed out while trying to fulfill the request. The request can be retried.

  • ErrCodeInvalidMarkerException "InvalidMarkerException" The request was rejected because the marker that specifies where pagination should next begin is not valid.

  • ErrCodeInternalException "KMSInternalException" The request was rejected because an internal exception occurred. The request can be retried.

  • ErrCodeInvalidArnException "InvalidArnException" The request was rejected because a specified ARN was not valid.

  • ErrCodeNotFoundException "NotFoundException" The request was rejected because the specified entity or resource could not be found.

See also, https://docs.aws.amazon.com/goto/WebAPI/kms-2014-11-01/ListAliases

Example

KMS ListAliases shared00

To list aliases

The following example lists aliases.

{ svc := kms.New(session.New()) input := &kms.ListAliasesInput{} result, err := svc.ListAliases(input) if err != nil { if aerr, ok := err.(awserr.Error); ok { switch aerr.Code() { case kms.ErrCodeDependencyTimeoutException: fmt.Println(kms.ErrCodeDependencyTimeoutException, aerr.Error()) case kms.ErrCodeInvalidMarkerException: fmt.Println(kms.ErrCodeInvalidMarkerException, aerr.Error()) case kms.ErrCodeInternalException: fmt.Println(kms.ErrCodeInternalException, aerr.Error()) case kms.ErrCodeInvalidArnException: fmt.Println(kms.ErrCodeInvalidArnException, aerr.Error()) case kms.ErrCodeNotFoundException: fmt.Println(kms.ErrCodeNotFoundException, aerr.Error()) default: fmt.Println(aerr.Error()) } } else { fmt.Println(err.Error()) } return } fmt.Println(result) }

ListAliasesPages

func (c *KMS) ListAliasesPages(input *ListAliasesInput, fn func(*ListAliasesOutput, bool) bool) error

ListAliasesPages iterates over the pages of a ListAliases operation, calling the "fn" function with the response data for each page. To stop iterating, return false from the fn function.

See ListAliases method for more information on how to use this operation.

Note: This operation can generate multiple requests to a service.

// Example iterating over at most 3 pages of a ListAliases operation. pageNum := 0 err := client.ListAliasesPages(params, func(page *ListAliasesOutput, lastPage bool) bool { pageNum++ fmt.Println(page) return pageNum <= 3 })

See Also

For more information about using this API, see AWS API Documentation.

ListAliasesPagesWithContext

func (c *KMS) ListAliasesPagesWithContext(ctx aws.Context, input *ListAliasesInput, fn func(*ListAliasesOutput, bool) bool, opts ...request.Option) error

ListAliasesPagesWithContext same as ListAliasesPages except it takes a Context and allows setting request options on the pages.

The context must be non-nil and will be used for request cancellation. If the context is nil a panic will occur. In the future the SDK may create sub-contexts for http.Requests. See https://golang.org/pkg/context/ for more information on using Contexts.

See Also

For more information about using this API, see AWS API Documentation.

ListAliasesRequest

func (c *KMS) ListAliasesRequest(input *ListAliasesInput) (req *request.Request, output *ListAliasesOutput)

ListAliasesRequest generates a "aws/request.Request" representing the client's request for the ListAliases operation. The "output" return value will be populated with the request's response once the request completes successfully.

Use "Send" method on the returned Request to send the API call to the service. the "output" return value is not valid until after Send returns without error.

See ListAliases for more information on using the ListAliases API call, and error handling.

This method is useful when you want to inject custom logic or configuration into the SDK's request lifecycle. Such as custom headers, or retry logic.

// Example sending a request using the ListAliasesRequest method. req, resp := client.ListAliasesRequest(params) err := req.Send() if err == nil { // resp is now filled fmt.Println(resp) }

See also, https://docs.aws.amazon.com/goto/WebAPI/kms-2014-11-01/ListAliases

ListAliasesWithContext

func (c *KMS) ListAliasesWithContext(ctx aws.Context, input *ListAliasesInput, opts ...request.Option) (*ListAliasesOutput, error)

ListAliasesWithContext is the same as ListAliases with the addition of the ability to pass a context and additional request options.

See ListAliases for details on how to use this API operation.

The context must be non-nil and will be used for request cancellation. If the context is nil a panic will occur. In the future the SDK may create sub-contexts for http.Requests. See https://golang.org/pkg/context/ for more information on using Contexts.

See Also

For more information about using this API, see AWS API Documentation.

ListGrants

func (c *KMS) ListGrants(input *ListGrantsInput) (*ListGrantsResponse, error)

ListGrants API operation for AWS Key Management Service.

Gets a list of all grants for the specified customer master key (CMK).

To perform this operation on a CMK in a different AWS account, specify the key ARN in the value of the KeyId parameter.

Returns awserr.Error for service API and SDK errors. Use runtime type assertions with awserr.Error's Code and Message methods to get detailed information about the error.

See the AWS API reference guide for AWS Key Management Service's API operation ListGrants for usage and error information.

Returned Error Codes:

  • ErrCodeNotFoundException "NotFoundException" The request was rejected because the specified entity or resource could not be found.

  • ErrCodeDependencyTimeoutException "DependencyTimeoutException" The system timed out while trying to fulfill the request. The request can be retried.

  • ErrCodeInvalidMarkerException "InvalidMarkerException" The request was rejected because the marker that specifies where pagination should next begin is not valid.

  • ErrCodeInvalidArnException "InvalidArnException" The request was rejected because a specified ARN was not valid.

  • ErrCodeInternalException "KMSInternalException" The request was rejected because an internal exception occurred. The request can be retried.

  • ErrCodeInvalidStateException "KMSInvalidStateException" The request was rejected because the state of the specified resource is not valid for this request.

For more information about how key state affects the use of a CMK, see How Key State Affects Use of a Customer Master Key (http://docs.aws.amazon.com/kms/latest/developerguide/key-state.html) in the AWS Key Management Service Developer Guide.

See also, https://docs.aws.amazon.com/goto/WebAPI/kms-2014-11-01/ListGrants

Example

KMS ListGrants shared00

To list grants for a customer master key (CMK)

The following example lists grants for the specified CMK.

{ svc := kms.New(session.New()) input := &kms.ListGrantsInput{ KeyId: aws.String("1234abcd-12ab-34cd-56ef-1234567890ab"), } result, err := svc.ListGrants(input) if err != nil { if aerr, ok := err.(awserr.Error); ok { switch aerr.Code() { case kms.ErrCodeNotFoundException: fmt.Println(kms.ErrCodeNotFoundException, aerr.Error()) case kms.ErrCodeDependencyTimeoutException: fmt.Println(kms.ErrCodeDependencyTimeoutException, aerr.Error()) case kms.ErrCodeInvalidMarkerException: fmt.Println(kms.ErrCodeInvalidMarkerException, aerr.Error()) case kms.ErrCodeInvalidArnException: fmt.Println(kms.ErrCodeInvalidArnException, aerr.Error()) case kms.ErrCodeInternalException: fmt.Println(kms.ErrCodeInternalException, aerr.Error()) case kms.ErrCodeInvalidStateException: fmt.Println(kms.ErrCodeInvalidStateException, aerr.Error()) default: fmt.Println(aerr.Error()) } } else { fmt.Println(err.Error()) } return } fmt.Println(result) }

ListGrantsPages

func (c *KMS) ListGrantsPages(input *ListGrantsInput, fn func(*ListGrantsResponse, bool) bool) error

ListGrantsPages iterates over the pages of a ListGrants operation, calling the "fn" function with the response data for each page. To stop iterating, return false from the fn function.

See ListGrants method for more information on how to use this operation.

Note: This operation can generate multiple requests to a service.

// Example iterating over at most 3 pages of a ListGrants operation. pageNum := 0 err := client.ListGrantsPages(params, func(page *ListGrantsResponse, lastPage bool) bool { pageNum++ fmt.Println(page) return pageNum <= 3 })

See Also

For more information about using this API, see AWS API Documentation.

ListGrantsPagesWithContext

func (c *KMS) ListGrantsPagesWithContext(ctx aws.Context, input *ListGrantsInput, fn func(*ListGrantsResponse, bool) bool, opts ...request.Option) error

ListGrantsPagesWithContext same as ListGrantsPages except it takes a Context and allows setting request options on the pages.

The context must be non-nil and will be used for request cancellation. If the context is nil a panic will occur. In the future the SDK may create sub-contexts for http.Requests. See https://golang.org/pkg/context/ for more information on using Contexts.

See Also

For more information about using this API, see AWS API Documentation.

ListGrantsRequest

func (c *KMS) ListGrantsRequest(input *ListGrantsInput) (req *request.Request, output *ListGrantsResponse)

ListGrantsRequest generates a "aws/request.Request" representing the client's request for the ListGrants operation. The "output" return value will be populated with the request's response once the request completes successfully.

Use "Send" method on the returned Request to send the API call to the service. the "output" return value is not valid until after Send returns without error.

See ListGrants for more information on using the ListGrants API call, and error handling.

This method is useful when you want to inject custom logic or configuration into the SDK's request lifecycle. Such as custom headers, or retry logic.

// Example sending a request using the ListGrantsRequest method. req, resp := client.ListGrantsRequest(params) err := req.Send() if err == nil { // resp is now filled fmt.Println(resp) }

See also, https://docs.aws.amazon.com/goto/WebAPI/kms-2014-11-01/ListGrants

ListGrantsWithContext

func (c *KMS) ListGrantsWithContext(ctx aws.Context, input *ListGrantsInput, opts ...request.Option) (*ListGrantsResponse, error)

ListGrantsWithContext is the same as ListGrants with the addition of the ability to pass a context and additional request options.

See ListGrants for details on how to use this API operation.

The context must be non-nil and will be used for request cancellation. If the context is nil a panic will occur. In the future the SDK may create sub-contexts for http.Requests. See https://golang.org/pkg/context/ for more information on using Contexts.

See Also

For more information about using this API, see AWS API Documentation.

ListKeyPolicies

func (c *KMS) ListKeyPolicies(input *ListKeyPoliciesInput) (*ListKeyPoliciesOutput, error)

ListKeyPolicies API operation for AWS Key Management Service.

Gets the names of the key policies that are attached to a customer master key (CMK). This operation is designed to get policy names that you can use in a GetKeyPolicy operation. However, the only valid policy name is default. You cannot perform this operation on a CMK in a different AWS account.

Returns awserr.Error for service API and SDK errors. Use runtime type assertions with awserr.Error's Code and Message methods to get detailed information about the error.

See the AWS API reference guide for AWS Key Management Service's API operation ListKeyPolicies for usage and error information.

Returned Error Codes:

  • ErrCodeNotFoundException "NotFoundException" The request was rejected because the specified entity or resource could not be found.

  • ErrCodeInvalidArnException "InvalidArnException" The request was rejected because a specified ARN was not valid.

  • ErrCodeDependencyTimeoutException "DependencyTimeoutException" The system timed out while trying to fulfill the request. The request can be retried.

  • ErrCodeInternalException "KMSInternalException" The request was rejected because an internal exception occurred. The request can be retried.

  • ErrCodeInvalidStateException "KMSInvalidStateException" The request was rejected because the state of the specified resource is not valid for this request.

For more information about how key state affects the use of a CMK, see How Key State Affects Use of a Customer Master Key (http://docs.aws.amazon.com/kms/latest/developerguide/key-state.html) in the AWS Key Management Service Developer Guide.

See also, https://docs.aws.amazon.com/goto/WebAPI/kms-2014-11-01/ListKeyPolicies

Example

KMS ListKeyPolicies shared00

To list key policies for a customer master key (CMK)

The following example lists key policies for the specified CMK.

{ svc := kms.New(session.New()) input := &kms.ListKeyPoliciesInput{ KeyId: aws.String("1234abcd-12ab-34cd-56ef-1234567890ab"), } result, err := svc.ListKeyPolicies(input) if err != nil { if aerr, ok := err.(awserr.Error); ok { switch aerr.Code() { case kms.ErrCodeNotFoundException: fmt.Println(kms.ErrCodeNotFoundException, aerr.Error()) case kms.ErrCodeInvalidArnException: fmt.Println(kms.ErrCodeInvalidArnException, aerr.Error()) case kms.ErrCodeDependencyTimeoutException: fmt.Println(kms.ErrCodeDependencyTimeoutException, aerr.Error()) case kms.ErrCodeInternalException: fmt.Println(kms.ErrCodeInternalException, aerr.Error()) case kms.ErrCodeInvalidStateException: fmt.Println(kms.ErrCodeInvalidStateException, aerr.Error()) default: fmt.Println(aerr.Error()) } } else { fmt.Println(err.Error()) } return } fmt.Println(result) }

ListKeyPoliciesPages

func (c *KMS) ListKeyPoliciesPages(input *ListKeyPoliciesInput, fn func(*ListKeyPoliciesOutput, bool) bool) error

ListKeyPoliciesPages iterates over the pages of a ListKeyPolicies operation, calling the "fn" function with the response data for each page. To stop iterating, return false from the fn function.

See ListKeyPolicies method for more information on how to use this operation.

Note: This operation can generate multiple requests to a service.

// Example iterating over at most 3 pages of a ListKeyPolicies operation. pageNum := 0 err := client.ListKeyPoliciesPages(params, func(page *ListKeyPoliciesOutput, lastPage bool) bool { pageNum++ fmt.Println(page) return pageNum <= 3 })

See Also

For more information about using this API, see AWS API Documentation.

ListKeyPoliciesPagesWithContext

func (c *KMS) ListKeyPoliciesPagesWithContext(ctx aws.Context, input *ListKeyPoliciesInput, fn func(*ListKeyPoliciesOutput, bool) bool, opts ...request.Option) error

ListKeyPoliciesPagesWithContext same as ListKeyPoliciesPages except it takes a Context and allows setting request options on the pages.

The context must be non-nil and will be used for request cancellation. If the context is nil a panic will occur. In the future the SDK may create sub-contexts for http.Requests. See https://golang.org/pkg/context/ for more information on using Contexts.

See Also

For more information about using this API, see AWS API Documentation.

ListKeyPoliciesRequest

func (c *KMS) ListKeyPoliciesRequest(input *ListKeyPoliciesInput) (req *request.Request, output *ListKeyPoliciesOutput)

ListKeyPoliciesRequest generates a "aws/request.Request" representing the client's request for the ListKeyPolicies operation. The "output" return value will be populated with the request's response once the request completes successfully.

Use "Send" method on the returned Request to send the API call to the service. the "output" return value is not valid until after Send returns without error.

See ListKeyPolicies for more information on using the ListKeyPolicies API call, and error handling.

This method is useful when you want to inject custom logic or configuration into the SDK's request lifecycle. Such as custom headers, or retry logic.

// Example sending a request using the ListKeyPoliciesRequest method. req, resp := client.ListKeyPoliciesRequest(params) err := req.Send() if err == nil { // resp is now filled fmt.Println(resp) }

See also, https://docs.aws.amazon.com/goto/WebAPI/kms-2014-11-01/ListKeyPolicies

ListKeyPoliciesWithContext

func (c *KMS) ListKeyPoliciesWithContext(ctx aws.Context, input *ListKeyPoliciesInput, opts ...request.Option) (*ListKeyPoliciesOutput, error)

ListKeyPoliciesWithContext is the same as ListKeyPolicies with the addition of the ability to pass a context and additional request options.

See ListKeyPolicies for details on how to use this API operation.

The context must be non-nil and will be used for request cancellation. If the context is nil a panic will occur. In the future the SDK may create sub-contexts for http.Requests. See https://golang.org/pkg/context/ for more information on using Contexts.

See Also

For more information about using this API, see AWS API Documentation.

ListKeys

func (c *KMS) ListKeys(input *ListKeysInput) (*ListKeysOutput, error)

ListKeys API operation for AWS Key Management Service.

Gets a list of all customer master keys (CMKs) in the caller's AWS account and region.

Returns awserr.Error for service API and SDK errors. Use runtime type assertions with awserr.Error's Code and Message methods to get detailed information about the error.

See the AWS API reference guide for AWS Key Management Service's API operation ListKeys for usage and error information.

Returned Error Codes:

  • ErrCodeDependencyTimeoutException "DependencyTimeoutException" The system timed out while trying to fulfill the request. The request can be retried.

  • ErrCodeInternalException "KMSInternalException" The request was rejected because an internal exception occurred. The request can be retried.

  • ErrCodeInvalidMarkerException "InvalidMarkerException" The request was rejected because the marker that specifies where pagination should next begin is not valid.

See also, https://docs.aws.amazon.com/goto/WebAPI/kms-2014-11-01/ListKeys

Example

KMS ListKeys shared00

To list customer master keys (CMKs)

The following example lists CMKs.

{ svc := kms.New(session.New()) input := &kms.ListKeysInput{} result, err := svc.ListKeys(input) if err != nil { if aerr, ok := err.(awserr.Error); ok { switch aerr.Code() { case kms.ErrCodeDependencyTimeoutException: fmt.Println(kms.ErrCodeDependencyTimeoutException, aerr.Error()) case kms.ErrCodeInternalException: fmt.Println(kms.ErrCodeInternalException, aerr.Error()) case kms.ErrCodeInvalidMarkerException: fmt.Println(kms.ErrCodeInvalidMarkerException, aerr.Error()) default: fmt.Println(aerr.Error()) } } else { fmt.Println(err.Error()) } return } fmt.Println(result) }

ListKeysPages

func (c *KMS) ListKeysPages(input *ListKeysInput, fn func(*ListKeysOutput, bool) bool) error

ListKeysPages iterates over the pages of a ListKeys operation, calling the "fn" function with the response data for each page. To stop iterating, return false from the fn function.

See ListKeys method for more information on how to use this operation.

Note: This operation can generate multiple requests to a service.

// Example iterating over at most 3 pages of a ListKeys operation. pageNum := 0 err := client.ListKeysPages(params, func(page *ListKeysOutput, lastPage bool) bool { pageNum++ fmt.Println(page) return pageNum <= 3 })

See Also

For more information about using this API, see AWS API Documentation.

ListKeysPagesWithContext

func (c *KMS) ListKeysPagesWithContext(ctx aws.Context, input *ListKeysInput, fn func(*ListKeysOutput, bool) bool, opts ...request.Option) error

ListKeysPagesWithContext same as ListKeysPages except it takes a Context and allows setting request options on the pages.

The context must be non-nil and will be used for request cancellation. If the context is nil a panic will occur. In the future the SDK may create sub-contexts for http.Requests. See https://golang.org/pkg/context/ for more information on using Contexts.

See Also

For more information about using this API, see AWS API Documentation.

ListKeysRequest

func (c *KMS) ListKeysRequest(input *ListKeysInput) (req *request.Request, output *ListKeysOutput)

ListKeysRequest generates a "aws/request.Request" representing the client's request for the ListKeys operation. The "output" return value will be populated with the request's response once the request completes successfully.

Use "Send" method on the returned Request to send the API call to the service. the "output" return value is not valid until after Send returns without error.

See ListKeys for more information on using the ListKeys API call, and error handling.

This method is useful when you want to inject custom logic or configuration into the SDK's request lifecycle. Such as custom headers, or retry logic.

// Example sending a request using the ListKeysRequest method. req, resp := client.ListKeysRequest(params) err := req.Send() if err == nil { // resp is now filled fmt.Println(resp) }

See also, https://docs.aws.amazon.com/goto/WebAPI/kms-2014-11-01/ListKeys

ListKeysWithContext

func (c *KMS) ListKeysWithContext(ctx aws.Context, input *ListKeysInput, opts ...request.Option) (*ListKeysOutput, error)

ListKeysWithContext is the same as ListKeys with the addition of the ability to pass a context and additional request options.

See ListKeys for details on how to use this API operation.

The context must be non-nil and will be used for request cancellation. If the context is nil a panic will occur. In the future the SDK may create sub-contexts for http.Requests. See https://golang.org/pkg/context/ for more information on using Contexts.

See Also

For more information about using this API, see AWS API Documentation.

ListResourceTags

func (c *KMS) ListResourceTags(input *ListResourceTagsInput) (*ListResourceTagsOutput, error)

ListResourceTags API operation for AWS Key Management Service.

Returns a list of all tags for the specified customer master key (CMK).

You cannot perform this operation on a CMK in a different AWS account.

Returns awserr.Error for service API and SDK errors. Use runtime type assertions with awserr.Error's Code and Message methods to get detailed information about the error.

See the AWS API reference guide for AWS Key Management Service's API operation ListResourceTags for usage and error information.

Returned Error Codes:

  • ErrCodeInternalException "KMSInternalException" The request was rejected because an internal exception occurred. The request can be retried.

  • ErrCodeNotFoundException "NotFoundException" The request was rejected because the specified entity or resource could not be found.

  • ErrCodeInvalidArnException "InvalidArnException" The request was rejected because a specified ARN was not valid.

  • ErrCodeInvalidMarkerException "InvalidMarkerException" The request was rejected because the marker that specifies where pagination should next begin is not valid.

See also, https://docs.aws.amazon.com/goto/WebAPI/kms-2014-11-01/ListResourceTags

Example

KMS ListResourceTags shared00

To list tags for a customer master key (CMK)

The following example lists tags for a CMK.

{ svc := kms.New(session.New()) input := &kms.ListResourceTagsInput{ KeyId: aws.String("1234abcd-12ab-34cd-56ef-1234567890ab"), } result, err := svc.ListResourceTags(input) if err != nil { if aerr, ok := err.(awserr.Error); ok { switch aerr.Code() { case kms.ErrCodeInternalException: fmt.Println(kms.ErrCodeInternalException, aerr.Error()) case kms.ErrCodeNotFoundException: fmt.Println(kms.ErrCodeNotFoundException, aerr.Error()) case kms.ErrCodeInvalidArnException: fmt.Println(kms.ErrCodeInvalidArnException, aerr.Error()) case kms.ErrCodeInvalidMarkerException: fmt.Println(kms.ErrCodeInvalidMarkerException, aerr.Error()) default: fmt.Println(aerr.Error()) } } else { fmt.Println(err.Error()) } return } fmt.Println(result) }

ListResourceTagsRequest

func (c *KMS) ListResourceTagsRequest(input *ListResourceTagsInput) (req *request.Request, output *ListResourceTagsOutput)

ListResourceTagsRequest generates a "aws/request.Request" representing the client's request for the ListResourceTags operation. The "output" return value will be populated with the request's response once the request completes successfully.

Use "Send" method on the returned Request to send the API call to the service. the "output" return value is not valid until after Send returns without error.

See ListResourceTags for more information on using the ListResourceTags API call, and error handling.

This method is useful when you want to inject custom logic or configuration into the SDK's request lifecycle. Such as custom headers, or retry logic.

// Example sending a request using the ListResourceTagsRequest method. req, resp := client.ListResourceTagsRequest(params) err := req.Send() if err == nil { // resp is now filled fmt.Println(resp) }

See also, https://docs.aws.amazon.com/goto/WebAPI/kms-2014-11-01/ListResourceTags

ListResourceTagsWithContext

func (c *KMS) ListResourceTagsWithContext(ctx aws.Context, input *ListResourceTagsInput, opts ...request.Option) (*ListResourceTagsOutput, error)

ListResourceTagsWithContext is the same as ListResourceTags with the addition of the ability to pass a context and additional request options.

See ListResourceTags for details on how to use this API operation.

The context must be non-nil and will be used for request cancellation. If the context is nil a panic will occur. In the future the SDK may create sub-contexts for http.Requests. See https://golang.org/pkg/context/ for more information on using Contexts.

See Also

For more information about using this API, see AWS API Documentation.

ListRetirableGrants

func (c *KMS) ListRetirableGrants(input *ListRetirableGrantsInput) (*ListGrantsResponse, error)

ListRetirableGrants API operation for AWS Key Management Service.

Returns a list of all grants for which the grant's RetiringPrincipal matches the one specified.

A typical use is to list all grants that you are able to retire. To retire a grant, use RetireGrant.

Returns awserr.Error for service API and SDK errors. Use runtime type assertions with awserr.Error's Code and Message methods to get detailed information about the error.

See the AWS API reference guide for AWS Key Management Service's API operation ListRetirableGrants for usage and error information.

Returned Error Codes:

  • ErrCodeDependencyTimeoutException "DependencyTimeoutException" The system timed out while trying to fulfill the request. The request can be retried.

  • ErrCodeInvalidMarkerException "InvalidMarkerException" The request was rejected because the marker that specifies where pagination should next begin is not valid.

  • ErrCodeInvalidArnException "InvalidArnException" The request was rejected because a specified ARN was not valid.

  • ErrCodeNotFoundException "NotFoundException" The request was rejected because the specified entity or resource could not be found.

  • ErrCodeInternalException "KMSInternalException" The request was rejected because an internal exception occurred. The request can be retried.

See also, https://docs.aws.amazon.com/goto/WebAPI/kms-2014-11-01/ListRetirableGrants

Example

KMS ListRetirableGrants shared00

To list grants that the specified principal can retire

The following example lists the grants that the specified principal (identity) can retire.

{ svc := kms.New(session.New()) input := &kms.ListRetirableGrantsInput{ RetiringPrincipal: aws.String("arn:aws:iam::111122223333:role/ExampleRole"), } result, err := svc.ListRetirableGrants(input) if err != nil { if aerr, ok := err.(awserr.Error); ok { switch aerr.Code() { case kms.ErrCodeDependencyTimeoutException: fmt.Println(kms.ErrCodeDependencyTimeoutException, aerr.Error()) case kms.ErrCodeInvalidMarkerException: fmt.Println(kms.ErrCodeInvalidMarkerException, aerr.Error()) case kms.ErrCodeInvalidArnException: fmt.Println(kms.ErrCodeInvalidArnException, aerr.Error()) case kms.ErrCodeNotFoundException: fmt.Println(kms.ErrCodeNotFoundException, aerr.Error()) case kms.ErrCodeInternalException: fmt.Println(kms.ErrCodeInternalException, aerr.Error()) default: fmt.Println(aerr.Error()) } } else { fmt.Println(err.Error()) } return } fmt.Println(result) }

ListRetirableGrantsRequest

func (c *KMS) ListRetirableGrantsRequest(input *ListRetirableGrantsInput) (req *request.Request, output *ListGrantsResponse)

ListRetirableGrantsRequest generates a "aws/request.Request" representing the client's request for the ListRetirableGrants operation. The "output" return value will be populated with the request's response once the request completes successfully.

Use "Send" method on the returned Request to send the API call to the service. the "output" return value is not valid until after Send returns without error.

See ListRetirableGrants for more information on using the ListRetirableGrants API call, and error handling.

This method is useful when you want to inject custom logic or configuration into the SDK's request lifecycle. Such as custom headers, or retry logic.

// Example sending a request using the ListRetirableGrantsRequest method. req, resp := client.ListRetirableGrantsRequest(params) err := req.Send() if err == nil { // resp is now filled fmt.Println(resp) }

See also, https://docs.aws.amazon.com/goto/WebAPI/kms-2014-11-01/ListRetirableGrants

ListRetirableGrantsWithContext

func (c *KMS) ListRetirableGrantsWithContext(ctx aws.Context, input *ListRetirableGrantsInput, opts ...request.Option) (*ListGrantsResponse, error)

ListRetirableGrantsWithContext is the same as ListRetirableGrants with the addition of the ability to pass a context and additional request options.

See ListRetirableGrants for details on how to use this API operation.

The context must be non-nil and will be used for request cancellation. If the context is nil a panic will occur. In the future the SDK may create sub-contexts for http.Requests. See https://golang.org/pkg/context/ for more information on using Contexts.

See Also

For more information about using this API, see AWS API Documentation.

PutKeyPolicy

func (c *KMS) PutKeyPolicy(input *PutKeyPolicyInput) (*PutKeyPolicyOutput, error)

PutKeyPolicy API operation for AWS Key Management Service.

Attaches a key policy to the specified customer master key (CMK). You cannot perform this operation on a CMK in a different AWS account.

For more information about key policies, see Key Policies (https://docs.aws.amazon.com/kms/latest/developerguide/key-policies.html) in the AWS Key Management Service Developer Guide.

Returns awserr.Error for service API and SDK errors. Use runtime type assertions with awserr.Error's Code and Message methods to get detailed information about the error.

See the AWS API reference guide for AWS Key Management Service's API operation PutKeyPolicy for usage and error information.

Returned Error Codes:

  • ErrCodeNotFoundException "NotFoundException" The request was rejected because the specified entity or resource could not be found.

  • ErrCodeInvalidArnException "InvalidArnException" The request was rejected because a specified ARN was not valid.

  • ErrCodeMalformedPolicyDocumentException "MalformedPolicyDocumentException" The request was rejected because the specified policy is not syntactically or semantically correct.

  • ErrCodeDependencyTimeoutException "DependencyTimeoutException" The system timed out while trying to fulfill the request. The request can be retried.

  • ErrCodeUnsupportedOperationException "UnsupportedOperationException" The request was rejected because a specified parameter is not supported or a specified resource is not valid for this operation.

  • ErrCodeInternalException "KMSInternalException" The request was rejected because an internal exception occurred. The request can be retried.

  • ErrCodeInvalidStateException "KMSInvalidStateException" The request was rejected because the state of the specified resource is not valid for this request.

For more information about how key state affects the use of a CMK, see How Key State Affects Use of a Customer Master Key (http://docs.aws.amazon.com/kms/latest/developerguide/key-state.html) in the AWS Key Management Service Developer Guide.

See also, https://docs.aws.amazon.com/goto/WebAPI/kms-2014-11-01/PutKeyPolicy

Example

KMS PutKeyPolicy shared00

To attach a key policy to a customer master key (CMK)

The following example attaches a key policy to the specified CMK.

{ svc := kms.New(session.New()) input := &kms.PutKeyPolicyInput{ KeyId: aws.String("1234abcd-12ab-34cd-56ef-1234567890ab"), Policy: aws.String("{\n \"Version\": \"2012-10-17\",\n \"Id\": \"custom-policy-2016-12-07\",\n \"Statement\": [\n {\n \"Sid\": \"Enable IAM User Permissions\",\n \"Effect\": \"Allow\",\n \"Principal\": {\n \"AWS\": \"arn:aws:iam::111122223333:root\"\n },\n \"Action\": \"kms:*\",\n \"Resource\": \"*\"\n },\n {\n \"Sid\": \"Allow access for Key Administrators\",\n \"Effect\": \"Allow\",\n \"Principal\": {\n \"AWS\": [\n \"arn:aws:iam::111122223333:user/ExampleAdminUser\",\n \"arn:aws:iam::111122223333:role/ExampleAdminRole\"\n ]\n },\n \"Action\": [\n \"kms:Create*\",\n \"kms:Describe*\",\n \"kms:Enable*\",\n \"kms:List*\",\n \"kms:Put*\",\n \"kms:Update*\",\n \"kms:Revoke*\",\n \"kms:Disable*\",\n \"kms:Get*\",\n \"kms:Delete*\",\n \"kms:ScheduleKeyDeletion\",\n \"kms:CancelKeyDeletion\"\n ],\n \"Resource\": \"*\"\n },\n {\n \"Sid\": \"Allow use of the key\",\n \"Effect\": \"Allow\",\n \"Principal\": {\n \"AWS\": \"arn:aws:iam::111122223333:role/ExamplePowerUserRole\"\n },\n \"Action\": [\n \"kms:Encrypt\",\n \"kms:Decrypt\",\n \"kms:ReEncrypt*\",\n \"kms:GenerateDataKey*\",\n \"kms:DescribeKey\"\n ],\n \"Resource\": \"*\"\n },\n {\n \"Sid\": \"Allow attachment of persistent resources\",\n \"Effect\": \"Allow\",\n \"Principal\": {\n \"AWS\": \"arn:aws:iam::111122223333:role/ExamplePowerUserRole\"\n },\n \"Action\": [\n \"kms:CreateGrant\",\n \"kms:ListGrants\",\n \"kms:RevokeGrant\"\n ],\n \"Resource\": \"*\",\n \"Condition\": {\n \"Bool\": {\n \"kms:GrantIsForAWSResource\": \"true\"\n }\n }\n }\n ]\n}\n"), PolicyName: aws.String("default"), } result, err := svc.PutKeyPolicy(input) if err != nil { if aerr, ok := err.(awserr.Error); ok { switch aerr.Code() { case kms.ErrCodeNotFoundException: fmt.Println(kms.ErrCodeNotFoundException, aerr.Error()) case kms.ErrCodeInvalidArnException: fmt.Println(kms.ErrCodeInvalidArnException, aerr.Error()) case kms.ErrCodeMalformedPolicyDocumentException: fmt.Println(kms.ErrCodeMalformedPolicyDocumentException, aerr.Error()) case kms.ErrCodeDependencyTimeoutException: fmt.Println(kms.ErrCodeDependencyTimeoutException, aerr.Error()) case kms.ErrCodeUnsupportedOperationException: fmt.Println(kms.ErrCodeUnsupportedOperationException, aerr.Error()) case kms.ErrCodeInternalException: fmt.Println(kms.ErrCodeInternalException, aerr.Error()) case kms.ErrCodeLimitExceededException: fmt.Println(kms.ErrCodeLimitExceededException, aerr.Error()) case kms.ErrCodeInvalidStateException: fmt.Println(kms.ErrCodeInvalidStateException, aerr.Error()) default: fmt.Println(aerr.Error()) } } else { fmt.Println(err.Error()) } return } fmt.Println(result) }

PutKeyPolicyRequest

func (c *KMS) PutKeyPolicyRequest(input *PutKeyPolicyInput) (req *request.Request, output *PutKeyPolicyOutput)

PutKeyPolicyRequest generates a "aws/request.Request" representing the client's request for the PutKeyPolicy operation. The "output" return value will be populated with the request's response once the request completes successfully.

Use "Send" method on the returned Request to send the API call to the service. the "output" return value is not valid until after Send returns without error.

See PutKeyPolicy for more information on using the PutKeyPolicy API call, and error handling.

This method is useful when you want to inject custom logic or configuration into the SDK's request lifecycle. Such as custom headers, or retry logic.

// Example sending a request using the PutKeyPolicyRequest method. req, resp := client.PutKeyPolicyRequest(params) err := req.Send() if err == nil { // resp is now filled fmt.Println(resp) }

See also, https://docs.aws.amazon.com/goto/WebAPI/kms-2014-11-01/PutKeyPolicy

PutKeyPolicyWithContext

func (c *KMS) PutKeyPolicyWithContext(ctx aws.Context, input *PutKeyPolicyInput, opts ...request.Option) (*PutKeyPolicyOutput, error)

PutKeyPolicyWithContext is the same as PutKeyPolicy with the addition of the ability to pass a context and additional request options.

See PutKeyPolicy for details on how to use this API operation.

The context must be non-nil and will be used for request cancellation. If the context is nil a panic will occur. In the future the SDK may create sub-contexts for http.Requests. See https://golang.org/pkg/context/ for more information on using Contexts.

See Also

For more information about using this API, see AWS API Documentation.

ReEncrypt

func (c *KMS) ReEncrypt(input *ReEncryptInput) (*ReEncryptOutput, error)

ReEncrypt API operation for AWS Key Management Service.

Encrypts data on the server side with a new customer master key (CMK) without exposing the plaintext of the data on the client side. The data is first decrypted and then reencrypted. You can also use this operation to change the encryption context of a ciphertext.

You can reencrypt data using CMKs in different AWS accounts.

Unlike other operations, ReEncrypt is authorized twice, once as ReEncryptFrom on the source CMK and once as ReEncryptTo on the destination CMK. We recommend that you include the "kms:ReEncrypt*" permission in your key policies (https://docs.aws.amazon.com/kms/latest/developerguide/key-policies.html) to permit reencryption from or to the CMK. This permission is automatically included in the key policy when you create a CMK through the console, but you must include it manually when you create a CMK programmatically or when you set a key policy with the PutKeyPolicy operation.

The result of this operation varies with the key state of the CMK. For details, see How Key State Affects Use of a Customer Master Key (https://docs.aws.amazon.com/kms/latest/developerguide/key-state.html) in the AWS Key Management Service Developer Guide.

Returns awserr.Error for service API and SDK errors. Use runtime type assertions with awserr.Error's Code and Message methods to get detailed information about the error.

See the AWS API reference guide for AWS Key Management Service's API operation ReEncrypt for usage and error information.

Returned Error Codes:

  • ErrCodeNotFoundException "NotFoundException" The request was rejected because the specified entity or resource could not be found.

  • ErrCodeDisabledException "DisabledException" The request was rejected because the specified CMK is not enabled.

  • ErrCodeInvalidCiphertextException "InvalidCiphertextException" The request was rejected because the specified ciphertext, or additional authenticated data incorporated into the ciphertext, such as the encryption context, is corrupted, missing, or otherwise invalid.

  • ErrCodeKeyUnavailableException "KeyUnavailableException" The request was rejected because the specified CMK was not available. The request can be retried.

  • ErrCodeDependencyTimeoutException "DependencyTimeoutException" The system timed out while trying to fulfill the request. The request can be retried.

  • ErrCodeInvalidKeyUsageException "InvalidKeyUsageException" The request was rejected because the specified KeySpec value is not valid.

  • ErrCodeInvalidGrantTokenException "InvalidGrantTokenException" The request was rejected because the specified grant token is not valid.

  • ErrCodeInternalException "KMSInternalException" The request was rejected because an internal exception occurred. The request can be retried.

  • ErrCodeInvalidStateException "KMSInvalidStateException" The request was rejected because the state of the specified resource is not valid for this request.

For more information about how key state affects the use of a CMK, see How Key State Affects Use of a Customer Master Key (http://docs.aws.amazon.com/kms/latest/developerguide/key-state.html) in the AWS Key Management Service Developer Guide.

See also, https://docs.aws.amazon.com/goto/WebAPI/kms-2014-11-01/ReEncrypt

Example

KMS ReEncrypt shared00

To reencrypt data

The following example reencrypts data with the specified CMK.

{ svc := kms.New(session.New()) input := &kms.ReEncryptInput{ CiphertextBlob: []byte("<binary data>"), DestinationKeyId: aws.String("0987dcba-09fe-87dc-65ba-ab0987654321"), } result, err := svc.ReEncrypt(input) if err != nil { if aerr, ok := err.(awserr.Error); ok { switch aerr.Code() { case kms.ErrCodeNotFoundException: fmt.Println(kms.ErrCodeNotFoundException, aerr.Error()) case kms.ErrCodeDisabledException: fmt.Println(kms.ErrCodeDisabledException, aerr.Error()) case kms.ErrCodeInvalidCiphertextException: fmt.Println(kms.ErrCodeInvalidCiphertextException, aerr.Error()) case kms.ErrCodeKeyUnavailableException: fmt.Println(kms.ErrCodeKeyUnavailableException, aerr.Error()) case kms.ErrCodeDependencyTimeoutException: fmt.Println(kms.ErrCodeDependencyTimeoutException, aerr.Error()) case kms.ErrCodeInvalidKeyUsageException: fmt.Println(kms.ErrCodeInvalidKeyUsageException, aerr.Error()) case kms.ErrCodeInvalidGrantTokenException: fmt.Println(kms.ErrCodeInvalidGrantTokenException, aerr.Error()) case kms.ErrCodeInternalException: fmt.Println(kms.ErrCodeInternalException, aerr.Error()) case kms.ErrCodeInvalidStateException: fmt.Println(kms.ErrCodeInvalidStateException, aerr.Error()) default: fmt.Println(aerr.Error()) } } else { fmt.Println(err.Error()) } return } fmt.Println(result) }

ReEncryptRequest

func (c *KMS) ReEncryptRequest(input *ReEncryptInput) (req *request.Request, output *ReEncryptOutput)

ReEncryptRequest generates a "aws/request.Request" representing the client's request for the ReEncrypt operation. The "output" return value will be populated with the request's response once the request completes successfully.

Use "Send" method on the returned Request to send the API call to the service. the "output" return value is not valid until after Send returns without error.

See ReEncrypt for more information on using the ReEncrypt API call, and error handling.

This method is useful when you want to inject custom logic or configuration into the SDK's request lifecycle. Such as custom headers, or retry logic.

// Example sending a request using the ReEncryptRequest method. req, resp := client.ReEncryptRequest(params) err := req.Send() if err == nil { // resp is now filled fmt.Println(resp) }

See also, https://docs.aws.amazon.com/goto/WebAPI/kms-2014-11-01/ReEncrypt

ReEncryptWithContext

func (c *KMS) ReEncryptWithContext(ctx aws.Context, input *ReEncryptInput, opts ...request.Option) (*ReEncryptOutput, error)

ReEncryptWithContext is the same as ReEncrypt with the addition of the ability to pass a context and additional request options.

See ReEncrypt for details on how to use this API operation.

The context must be non-nil and will be used for request cancellation. If the context is nil a panic will occur. In the future the SDK may create sub-contexts for http.Requests. See https://golang.org/pkg/context/ for more information on using Contexts.

See Also

For more information about using this API, see AWS API Documentation.

RetireGrant

func (c *KMS) RetireGrant(input *RetireGrantInput) (*RetireGrantOutput, error)

RetireGrant API operation for AWS Key Management Service.

Retires a grant. To clean up, you can retire a grant when you're done using it. You should revoke a grant when you intend to actively deny operations that depend on it. The following are permitted to call this API:

  • The AWS account (root user) under which the grant was created

  • The RetiringPrincipal, if present in the grant

  • The GranteePrincipal, if RetireGrant is an operation specified in the grant

You must identify the grant to retire by its grant token or by a combination of the grant ID and the Amazon Resource Name (ARN) of the customer master key (CMK). A grant token is a unique variable-length base64-encoded string. A grant ID is a 64 character unique identifier of a grant. The CreateGrant operation returns both.

Returns awserr.Error for service API and SDK errors. Use runtime type assertions with awserr.Error's Code and Message methods to get detailed information about the error.

See the AWS API reference guide for AWS Key Management Service's API operation RetireGrant for usage and error information.

Returned Error Codes:

  • ErrCodeInvalidArnException "InvalidArnException" The request was rejected because a specified ARN was not valid.

  • ErrCodeInvalidGrantTokenException "InvalidGrantTokenException" The request was rejected because the specified grant token is not valid.

  • ErrCodeInvalidGrantIdException "InvalidGrantIdException" The request was rejected because the specified GrantId is not valid.

  • ErrCodeNotFoundException "NotFoundException" The request was rejected because the specified entity or resource could not be found.

  • ErrCodeDependencyTimeoutException "DependencyTimeoutException" The system timed out while trying to fulfill the request. The request can be retried.

  • ErrCodeInternalException "KMSInternalException" The request was rejected because an internal exception occurred. The request can be retried.

  • ErrCodeInvalidStateException "KMSInvalidStateException" The request was rejected because the state of the specified resource is not valid for this request.

For more information about how key state affects the use of a CMK, see How Key State Affects Use of a Customer Master Key (http://docs.aws.amazon.com/kms/latest/developerguide/key-state.html) in the AWS Key Management Service Developer Guide.

See also, https://docs.aws.amazon.com/goto/WebAPI/kms-2014-11-01/RetireGrant

Example

KMS RetireGrant shared00

To retire a grant

The following example retires a grant.

{ svc := kms.New(session.New()) input := &kms.RetireGrantInput{ GrantId: aws.String("0c237476b39f8bc44e45212e08498fbe3151305030726c0590dd8d3e9f3d6a60"), KeyId: aws.String("arn:aws:kms:us-east-2:444455556666:key/1234abcd-12ab-34cd-56ef-1234567890ab"), } result, err := svc.RetireGrant(input) if err != nil { if aerr, ok := err.(awserr.Error); ok { switch aerr.Code() { case kms.ErrCodeInvalidArnException: fmt.Println(kms.ErrCodeInvalidArnException, aerr.Error()) case kms.ErrCodeInvalidGrantTokenException: fmt.Println(kms.ErrCodeInvalidGrantTokenException, aerr.Error()) case kms.ErrCodeInvalidGrantIdException: fmt.Println(kms.ErrCodeInvalidGrantIdException, aerr.Error()) case kms.ErrCodeNotFoundException: fmt.Println(kms.ErrCodeNotFoundException, aerr.Error()) case kms.ErrCodeDependencyTimeoutException: fmt.Println(kms.ErrCodeDependencyTimeoutException, aerr.Error()) case kms.ErrCodeInternalException: fmt.Println(kms.ErrCodeInternalException, aerr.Error()) case kms.ErrCodeInvalidStateException: fmt.Println(kms.ErrCodeInvalidStateException, aerr.Error()) default: fmt.Println(aerr.Error()) } } else { fmt.Println(err.Error()) } return } fmt.Println(result) }

RetireGrantRequest

func (c *KMS) RetireGrantRequest(input *RetireGrantInput) (req *request.Request, output *RetireGrantOutput)

RetireGrantRequest generates a "aws/request.Request" representing the client's request for the RetireGrant operation. The "output" return value will be populated with the request's response once the request completes successfully.

Use "Send" method on the returned Request to send the API call to the service. the "output" return value is not valid until after Send returns without error.

See RetireGrant for more information on using the RetireGrant API call, and error handling.

This method is useful when you want to inject custom logic or configuration into the SDK's request lifecycle. Such as custom headers, or retry logic.

// Example sending a request using the RetireGrantRequest method. req, resp := client.RetireGrantRequest(params) err := req.Send() if err == nil { // resp is now filled fmt.Println(resp) }

See also, https://docs.aws.amazon.com/goto/WebAPI/kms-2014-11-01/RetireGrant

RetireGrantWithContext

func (c *KMS) RetireGrantWithContext(ctx aws.Context, input *RetireGrantInput, opts ...request.Option) (*RetireGrantOutput, error)

RetireGrantWithContext is the same as RetireGrant with the addition of the ability to pass a context and additional request options.

See RetireGrant for details on how to use this API operation.

The context must be non-nil and will be used for request cancellation. If the context is nil a panic will occur. In the future the SDK may create sub-contexts for http.Requests. See https://golang.org/pkg/context/ for more information on using Contexts.

See Also

For more information about using this API, see AWS API Documentation.

RevokeGrant

func (c *KMS) RevokeGrant(input *RevokeGrantInput) (*RevokeGrantOutput, error)

RevokeGrant API operation for AWS Key Management Service.

Revokes the specified grant for the specified customer master key (CMK). You can revoke a grant to actively deny operations that depend on it.

To perform this operation on a CMK in a different AWS account, specify the key ARN in the value of the KeyId parameter.

Returns awserr.Error for service API and SDK errors. Use runtime type assertions with awserr.Error's Code and Message methods to get detailed information about the error.

See the AWS API reference guide for AWS Key Management Service's API operation RevokeGrant for usage and error information.

Returned Error Codes:

  • ErrCodeNotFoundException "NotFoundException" The request was rejected because the specified entity or resource could not be found.

  • ErrCodeDependencyTimeoutException "DependencyTimeoutException" The system timed out while trying to fulfill the request. The request can be retried.

  • ErrCodeInvalidArnException "InvalidArnException" The request was rejected because a specified ARN was not valid.

  • ErrCodeInvalidGrantIdException "InvalidGrantIdException" The request was rejected because the specified GrantId is not valid.

  • ErrCodeInternalException "KMSInternalException" The request was rejected because an internal exception occurred. The request can be retried.

  • ErrCodeInvalidStateException "KMSInvalidStateException" The request was rejected because the state of the specified resource is not valid for this request.

For more information about how key state affects the use of a CMK, see How Key State Affects Use of a Customer Master Key (http://docs.aws.amazon.com/kms/latest/developerguide/key-state.html) in the AWS Key Management Service Developer Guide.

See also, https://docs.aws.amazon.com/goto/WebAPI/kms-2014-11-01/RevokeGrant

Example

KMS RevokeGrant shared00

To revoke a grant

The following example revokes a grant.

{ svc := kms.New(session.New()) input := &kms.RevokeGrantInput{ GrantId: aws.String("0c237476b39f8bc44e45212e08498fbe3151305030726c0590dd8d3e9f3d6a60"), KeyId: aws.String("1234abcd-12ab-34cd-56ef-1234567890ab"), } result, err := svc.RevokeGrant(input) if err != nil { if aerr, ok := err.(awserr.Error); ok { switch aerr.Code() { case kms.ErrCodeNotFoundException: fmt.Println(kms.ErrCodeNotFoundException, aerr.Error()) case kms.ErrCodeDependencyTimeoutException: fmt.Println(kms.ErrCodeDependencyTimeoutException, aerr.Error()) case kms.ErrCodeInvalidArnException: fmt.Println(kms.ErrCodeInvalidArnException, aerr.Error()) case kms.ErrCodeInvalidGrantIdException: fmt.Println(kms.ErrCodeInvalidGrantIdException, aerr.Error()) case kms.ErrCodeInternalException: fmt.Println(kms.ErrCodeInternalException, aerr.Error()) case kms.ErrCodeInvalidStateException: fmt.Println(kms.ErrCodeInvalidStateException, aerr.Error()) default: fmt.Println(aerr.Error()) } } else { fmt.Println(err.Error()) } return } fmt.Println(result) }

RevokeGrantRequest

func (c *KMS) RevokeGrantRequest(input *RevokeGrantInput) (req *request.Request, output *RevokeGrantOutput)

RevokeGrantRequest generates a "aws/request.Request" representing the client's request for the RevokeGrant operation. The "output" return value will be populated with the request's response once the request completes successfully.

Use "Send" method on the returned Request to send the API call to the service. the "output" return value is not valid until after Send returns without error.

See RevokeGrant for more information on using the RevokeGrant API call, and error handling.

This method is useful when you want to inject custom logic or configuration into the SDK's request lifecycle. Such as custom headers, or retry logic.

// Example sending a request using the RevokeGrantRequest method. req, resp := client.RevokeGrantRequest(params) err := req.Send() if err == nil { // resp is now filled fmt.Println(resp) }

See also, https://docs.aws.amazon.com/goto/WebAPI/kms-2014-11-01/RevokeGrant

RevokeGrantWithContext

func (c *KMS) RevokeGrantWithContext(ctx aws.Context, input *RevokeGrantInput, opts ...request.Option) (*RevokeGrantOutput, error)

RevokeGrantWithContext is the same as RevokeGrant with the addition of the ability to pass a context and additional request options.

See RevokeGrant for details on how to use this API operation.

The context must be non-nil and will be used for request cancellation. If the context is nil a panic will occur. In the future the SDK may create sub-contexts for http.Requests. See https://golang.org/pkg/context/ for more information on using Contexts.

See Also

For more information about using this API, see AWS API Documentation.

ScheduleKeyDeletion

func (c *KMS) ScheduleKeyDeletion(input *ScheduleKeyDeletionInput) (*ScheduleKeyDeletionOutput, error)

ScheduleKeyDeletion API operation for AWS Key Management Service.

Schedules the deletion of a customer master key (CMK). You may provide a waiting period, specified in days, before deletion occurs. If you do not provide a waiting period, the default period of 30 days is used. When this operation is successful, the key state of the CMK changes to PendingDeletion. Before the waiting period ends, you can use CancelKeyDeletion to cancel the deletion of the CMK. After the waiting period ends, AWS KMS deletes the CMK and all AWS KMS data associated with it, including all aliases that refer to it.

Deleting a CMK is a destructive and potentially dangerous operation. When a CMK is deleted, all data that was encrypted under the CMK is unrecoverable. To prevent the use of a CMK without deleting it, use DisableKey.

If you schedule deletion of a CMK from a custom key store (https://docs.aws.amazon.com/kms/latest/developerguide/key-store-overview.html), when the waiting period expires, ScheduleKeyDeletion deletes the CMK from AWS KMS. Then AWS KMS makes a best effort to delete the key material from the associated AWS CloudHSM cluster. However, you might need to manually delete the orphaned key material (https://docs.aws.amazon.com/kms/latest/developerguide/fix-keystore.html#fix-keystore-orphaned-key) from the cluster and its backups.

You cannot perform this operation on a CMK in a different AWS account.

For more information about scheduling a CMK for deletion, see Deleting Customer Master Keys (https://docs.aws.amazon.com/kms/latest/developerguide/deleting-keys.html) in the AWS Key Management Service Developer Guide.

The result of this operation varies with the key state of the CMK. For details, see How Key State Affects Use of a Customer Master Key (https://docs.aws.amazon.com/kms/latest/developerguide/key-state.html) in the AWS Key Management Service Developer Guide.

Returns awserr.Error for service API and SDK errors. Use runtime type assertions with awserr.Error's Code and Message methods to get detailed information about the error.

See the AWS API reference guide for AWS Key Management Service's API operation ScheduleKeyDeletion for usage and error information.

Returned Error Codes:

  • ErrCodeNotFoundException "NotFoundException" The request was rejected because the specified entity or resource could not be found.

  • ErrCodeInvalidArnException "InvalidArnException" The request was rejected because a specified ARN was not valid.

  • ErrCodeDependencyTimeoutException "DependencyTimeoutException" The system timed out while trying to fulfill the request. The request can be retried.

  • ErrCodeInternalException "KMSInternalException" The request was rejected because an internal exception occurred. The request can be retried.

  • ErrCodeInvalidStateException "KMSInvalidStateException" The request was rejected because the state of the specified resource is not valid for this request.

For more information about how key state affects the use of a CMK, see How Key State Affects Use of a Customer Master Key (http://docs.aws.amazon.com/kms/latest/developerguide/key-state.html) in the AWS Key Management Service Developer Guide.

See also, https://docs.aws.amazon.com/goto/WebAPI/kms-2014-11-01/ScheduleKeyDeletion

Example

KMS ScheduleKeyDeletion shared00

To schedule a customer master key (CMK) for deletion

The following example schedules the specified CMK for deletion.

{ svc := kms.New(session.New()) input := &kms.ScheduleKeyDeletionInput{ KeyId: aws.String("1234abcd-12ab-34cd-56ef-1234567890ab"), PendingWindowInDays: aws.Int64(7), } result, err := svc.ScheduleKeyDeletion(input) if err != nil { if aerr, ok := err.(awserr.Error); ok { switch aerr.Code() { case kms.ErrCodeNotFoundException: fmt.Println(kms.ErrCodeNotFoundException, aerr.Error()) case kms.ErrCodeInvalidArnException: fmt.Println(kms.ErrCodeInvalidArnException, aerr.Error()) case kms.ErrCodeDependencyTimeoutException: fmt.Println(kms.ErrCodeDependencyTimeoutException, aerr.Error()) case kms.ErrCodeInternalException: fmt.Println(kms.ErrCodeInternalException, aerr.Error()) case kms.ErrCodeInvalidStateException: fmt.Println(kms.ErrCodeInvalidStateException, aerr.Error()) default: fmt.Println(aerr.Error()) } } else { fmt.Println(err.Error()) } return } fmt.Println(result) }

ScheduleKeyDeletionRequest

func (c *KMS) ScheduleKeyDeletionRequest(input *ScheduleKeyDeletionInput) (req *request.Request, output *ScheduleKeyDeletionOutput)

ScheduleKeyDeletionRequest generates a "aws/request.Request" representing the client's request for the ScheduleKeyDeletion operation. The "output" return value will be populated with the request's response once the request completes successfully.

Use "Send" method on the returned Request to send the API call to the service. the "output" return value is not valid until after Send returns without error.

See ScheduleKeyDeletion for more information on using the ScheduleKeyDeletion API call, and error handling.

This method is useful when you want to inject custom logic or configuration into the SDK's request lifecycle. Such as custom headers, or retry logic.

// Example sending a request using the ScheduleKeyDeletionRequest method. req, resp := client.ScheduleKeyDeletionRequest(params) err := req.Send() if err == nil { // resp is now filled fmt.Println(resp) }

See also, https://docs.aws.amazon.com/goto/WebAPI/kms-2014-11-01/ScheduleKeyDeletion

ScheduleKeyDeletionWithContext

func (c *KMS) ScheduleKeyDeletionWithContext(ctx aws.Context, input *ScheduleKeyDeletionInput, opts ...request.Option) (*ScheduleKeyDeletionOutput, error)

ScheduleKeyDeletionWithContext is the same as ScheduleKeyDeletion with the addition of the ability to pass a context and additional request options.

See ScheduleKeyDeletion for details on how to use this API operation.

The context must be non-nil and will be used for request cancellation. If the context is nil a panic will occur. In the future the SDK may create sub-contexts for http.Requests. See https://golang.org/pkg/context/ for more information on using Contexts.

See Also

For more information about using this API, see AWS API Documentation.

TagResource

func (c *KMS) TagResource(input *TagResourceInput) (*TagResourceOutput, error)

TagResource API operation for AWS Key Management Service.

Adds or edits tags for a customer master key (CMK). You cannot perform this operation on a CMK in a different AWS account.

Each tag consists of a tag key and a tag value. Tag keys and tag values are both required, but tag values can be empty (null) strings.

You can only use a tag key once for each CMK. If you use the tag key again, AWS KMS replaces the current tag value with the specified value.

For information about the rules that apply to tag keys and tag values, see User-Defined Tag Restrictions (https://docs.aws.amazon.com/awsaccountbilling/latest/aboutv2/allocation-tag-restrictions.html) in the AWS Billing and Cost Management User Guide.

The result of this operation varies with the key state of the CMK. For details, see How Key State Affects Use of a Customer Master Key (https://docs.aws.amazon.com/kms/latest/developerguide/key-state.html) in the AWS Key Management Service Developer Guide.

Returns awserr.Error for service API and SDK errors. Use runtime type assertions with awserr.Error's Code and Message methods to get detailed information about the error.

See the AWS API reference guide for AWS Key Management Service's API operation TagResource for usage and error information.

Returned Error Codes:

  • ErrCodeInternalException "KMSInternalException" The request was rejected because an internal exception occurred. The request can be retried.

  • ErrCodeNotFoundException "NotFoundException" The request was rejected because the specified entity or resource could not be found.

  • ErrCodeInvalidArnException "InvalidArnException" The request was rejected because a specified ARN was not valid.

  • ErrCodeInvalidStateException "KMSInvalidStateException" The request was rejected because the state of the specified resource is not valid for this request.

For more information about how key state affects the use of a CMK, see How Key State Affects Use of a Customer Master Key (http://docs.aws.amazon.com/kms/latest/developerguide/key-state.html) in the AWS Key Management Service Developer Guide.
  • ErrCodeTagException "TagException" The request was rejected because one or more tags are not valid.

See also, https://docs.aws.amazon.com/goto/WebAPI/kms-2014-11-01/TagResource

Example

KMS TagResource shared00

To tag a customer master key (CMK)

The following example tags a CMK.

{ svc := kms.New(session.New()) input := &kms.TagResourceInput{ KeyId: aws.String("1234abcd-12ab-34cd-56ef-1234567890ab"), Tags: []*kms.Tag{ { TagKey: aws.String("Purpose"), TagValue: aws.String("Test"), }, }, } result, err := svc.TagResource(input) if err != nil { if aerr, ok := err.(awserr.Error); ok { switch aerr.Code() { case kms.ErrCodeInternalException: fmt.Println(kms.ErrCodeInternalException, aerr.Error()) case kms.ErrCodeNotFoundException: fmt.Println(kms.ErrCodeNotFoundException, aerr.Error()) case kms.ErrCodeInvalidArnException: fmt.Println(kms.ErrCodeInvalidArnException, aerr.Error()) case kms.ErrCodeInvalidStateException: fmt.Println(kms.ErrCodeInvalidStateException, aerr.Error()) case kms.ErrCodeLimitExceededException: fmt.Println(kms.ErrCodeLimitExceededException, aerr.Error()) case kms.ErrCodeTagException: fmt.Println(kms.ErrCodeTagException, aerr.Error()) default: fmt.Println(aerr.Error()) } } else { fmt.Println(err.Error()) } return } fmt.Println(result) }

TagResourceRequest

func (c *KMS) TagResourceRequest(input *TagResourceInput) (req *request.Request, output *TagResourceOutput)

TagResourceRequest generates a "aws/request.Request" representing the client's request for the TagResource operation. The "output" return value will be populated with the request's response once the request completes successfully.

Use "Send" method on the returned Request to send the API call to the service. the "output" return value is not valid until after Send returns without error.

See TagResource for more information on using the TagResource API call, and error handling.

This method is useful when you want to inject custom logic or configuration into the SDK's request lifecycle. Such as custom headers, or retry logic.

// Example sending a request using the TagResourceRequest method. req, resp := client.TagResourceRequest(params) err := req.Send() if err == nil { // resp is now filled fmt.Println(resp) }

See also, https://docs.aws.amazon.com/goto/WebAPI/kms-2014-11-01/TagResource

TagResourceWithContext

func (c *KMS) TagResourceWithContext(ctx aws.Context, input *TagResourceInput, opts ...request.Option) (*TagResourceOutput, error)

TagResourceWithContext is the same as TagResource with the addition of the ability to pass a context and additional request options.

See TagResource for details on how to use this API operation.

The context must be non-nil and will be used for request cancellation. If the context is nil a panic will occur. In the future the SDK may create sub-contexts for http.Requests. See https://golang.org/pkg/context/ for more information on using Contexts.

See Also

For more information about using this API, see AWS API Documentation.

UntagResource

func (c *KMS) UntagResource(input *UntagResourceInput) (*UntagResourceOutput, error)

UntagResource API operation for AWS Key Management Service.

Removes the specified tags from the specified customer master key (CMK). You cannot perform this operation on a CMK in a different AWS account.

To remove a tag, specify the tag key. To change the tag value of an existing tag key, use TagResource.

The result of this operation varies with the key state of the CMK. For details, see How Key State Affects Use of a Customer Master Key (https://docs.aws.amazon.com/kms/latest/developerguide/key-state.html) in the AWS Key Management Service Developer Guide.

Returns awserr.Error for service API and SDK errors. Use runtime type assertions with awserr.Error's Code and Message methods to get detailed information about the error.

See the AWS API reference guide for AWS Key Management Service's API operation UntagResource for usage and error information.

Returned Error Codes:

  • ErrCodeInternalException "KMSInternalException" The request was rejected because an internal exception occurred. The request can be retried.

  • ErrCodeNotFoundException "NotFoundException" The request was rejected because the specified entity or resource could not be found.

  • ErrCodeInvalidArnException "InvalidArnException" The request was rejected because a specified ARN was not valid.

  • ErrCodeInvalidStateException "KMSInvalidStateException" The request was rejected because the state of the specified resource is not valid for this request.

For more information about how key state affects the use of a CMK, see How Key State Affects Use of a Customer Master Key (http://docs.aws.amazon.com/kms/latest/developerguide/key-state.html) in the AWS Key Management Service Developer Guide.
  • ErrCodeTagException "TagException" The request was rejected because one or more tags are not valid.

See also, https://docs.aws.amazon.com/goto/WebAPI/kms-2014-11-01/UntagResource

Example

KMS UntagResource shared00

To remove tags from a customer master key (CMK)

The following example removes tags from a CMK.

{ svc := kms.New(session.New()) input := &kms.UntagResourceInput{ KeyId: aws.String("1234abcd-12ab-34cd-56ef-1234567890ab"), TagKeys: []*string{ aws.String("Purpose"), aws.String("CostCenter"), }, } result, err := svc.UntagResource(input) if err != nil { if aerr, ok := err.(awserr.Error); ok { switch aerr.Code() { case kms.ErrCodeInternalException: fmt.Println(kms.ErrCodeInternalException, aerr.Error()) case kms.ErrCodeNotFoundException: fmt.Println(kms.ErrCodeNotFoundException, aerr.Error()) case kms.ErrCodeInvalidArnException: fmt.Println(kms.ErrCodeInvalidArnException, aerr.Error()) case kms.ErrCodeInvalidStateException: fmt.Println(kms.ErrCodeInvalidStateException, aerr.Error()) case kms.ErrCodeTagException: fmt.Println(kms.ErrCodeTagException, aerr.Error()) default: fmt.Println(aerr.Error()) } } else { fmt.Println(err.Error()) } return } fmt.Println(result) }

UntagResourceRequest

func (c *KMS) UntagResourceRequest(input *UntagResourceInput) (req *request.Request, output *UntagResourceOutput)

UntagResourceRequest generates a "aws/request.Request" representing the client's request for the UntagResource operation. The "output" return value will be populated with the request's response once the request completes successfully.

Use "Send" method on the returned Request to send the API call to the service. the "output" return value is not valid until after Send returns without error.

See UntagResource for more information on using the UntagResource API call, and error handling.

This method is useful when you want to inject custom logic or configuration into the SDK's request lifecycle. Such as custom headers, or retry logic.

// Example sending a request using the UntagResourceRequest method. req, resp := client.UntagResourceRequest(params) err := req.Send() if err == nil { // resp is now filled fmt.Println(resp) }

See also, https://docs.aws.amazon.com/goto/WebAPI/kms-2014-11-01/UntagResource

UntagResourceWithContext

func (c *KMS) UntagResourceWithContext(ctx aws.Context, input *UntagResourceInput, opts ...request.Option) (*UntagResourceOutput, error)

UntagResourceWithContext is the same as UntagResource with the addition of the ability to pass a context and additional request options.

See UntagResource for details on how to use this API operation.

The context must be non-nil and will be used for request cancellation. If the context is nil a panic will occur. In the future the SDK may create sub-contexts for http.Requests. See https://golang.org/pkg/context/ for more information on using Contexts.

See Also

For more information about using this API, see AWS API Documentation.

UpdateAlias

func (c *KMS) UpdateAlias(input *UpdateAliasInput) (*UpdateAliasOutput, error)

UpdateAlias API operation for AWS Key Management Service.

Associates an existing alias with a different customer master key (CMK). Each CMK can have multiple aliases, but the aliases must be unique within the account and region. You cannot perform this operation on an alias in a different AWS account.

This operation works only on existing aliases. To change the alias of a CMK to a new value, use CreateAlias to create a new alias and DeleteAlias to delete the old alias.

Because an alias is not a property of a CMK, you can create, update, and delete the aliases of a CMK without affecting the CMK. Also, aliases do not appear in the response from the DescribeKey operation. To get the aliases of all CMKs in the account, use the ListAliases operation.

An alias name can contain only alphanumeric characters, forward slashes (/), underscores (_), and dashes (-). An alias must start with the word alias followed by a forward slash (alias/). The alias name can contain only alphanumeric characters, forward slashes (/), underscores (_), and dashes (-). Alias names cannot begin with aws; that alias name prefix is reserved by Amazon Web Services (AWS).

The result of this operation varies with the key state of the CMK. For details, see How Key State Affects Use of a Customer Master Key (https://docs.aws.amazon.com/kms/latest/developerguide/key-state.html) in the AWS Key Management Service Developer Guide.

Returns awserr.Error for service API and SDK errors. Use runtime type assertions with awserr.Error's Code and Message methods to get detailed information about the error.

See the AWS API reference guide for AWS Key Management Service's API operation UpdateAlias for usage and error information.

Returned Error Codes:

  • ErrCodeDependencyTimeoutException "DependencyTimeoutException" The system timed out while trying to fulfill the request. The request can be retried.

  • ErrCodeNotFoundException "NotFoundException" The request was rejected because the specified entity or resource could not be found.

  • ErrCodeInternalException "KMSInternalException" The request was rejected because an internal exception occurred. The request can be retried.

  • ErrCodeInvalidStateException "KMSInvalidStateException" The request was rejected because the state of the specified resource is not valid for this request.

For more information about how key state affects the use of a CMK, see How Key State Affects Use of a Customer Master Key (http://docs.aws.amazon.com/kms/latest/developerguide/key-state.html) in the AWS Key Management Service Developer Guide.

See also, https://docs.aws.amazon.com/goto/WebAPI/kms-2014-11-01/UpdateAlias

Example

KMS UpdateAlias shared00

To update an alias

The following example updates the specified alias to refer to the specified customer master key (CMK).

{ svc := kms.New(session.New()) input := &kms.UpdateAliasInput{ AliasName: aws.String("alias/ExampleAlias"), TargetKeyId: aws.String("1234abcd-12ab-34cd-56ef-1234567890ab"), } result, err := svc.UpdateAlias(input) if err != nil { if aerr, ok := err.(awserr.Error); ok { switch aerr.Code() { case kms.ErrCodeDependencyTimeoutException: fmt.Println(kms.ErrCodeDependencyTimeoutException, aerr.Error()) case kms.ErrCodeNotFoundException: fmt.Println(kms.ErrCodeNotFoundException, aerr.Error()) case kms.ErrCodeInternalException: fmt.Println(kms.ErrCodeInternalException, aerr.Error()) case kms.ErrCodeInvalidStateException: fmt.Println(kms.ErrCodeInvalidStateException, aerr.Error()) default: fmt.Println(aerr.Error()) } } else { fmt.Println(err.Error()) } return } fmt.Println(result) }

UpdateAliasRequest

func (c *KMS) UpdateAliasRequest(input *UpdateAliasInput) (req *request.Request, output *UpdateAliasOutput)

UpdateAliasRequest generates a "aws/request.Request" representing the client's request for the UpdateAlias operation. The "output" return value will be populated with the request's response once the request completes successfully.

Use "Send" method on the returned Request to send the API call to the service. the "output" return value is not valid until after Send returns without error.

See UpdateAlias for more information on using the UpdateAlias API call, and error handling.

This method is useful when you want to inject custom logic or configuration into the SDK's request lifecycle. Such as custom headers, or retry logic.

// Example sending a request using the UpdateAliasRequest method. req, resp := client.UpdateAliasRequest(params) err := req.Send() if err == nil { // resp is now filled fmt.Println(resp) }

See also, https://docs.aws.amazon.com/goto/WebAPI/kms-2014-11-01/UpdateAlias

UpdateAliasWithContext

func (c *KMS) UpdateAliasWithContext(ctx aws.Context, input *UpdateAliasInput, opts ...request.Option) (*UpdateAliasOutput, error)

UpdateAliasWithContext is the same as UpdateAlias with the addition of the ability to pass a context and additional request options.

See UpdateAlias for details on how to use this API operation.

The context must be non-nil and will be used for request cancellation. If the context is nil a panic will occur. In the future the SDK may create sub-contexts for http.Requests. See https://golang.org/pkg/context/ for more information on using Contexts.

See Also

For more information about using this API, see AWS API Documentation.

UpdateCustomKeyStore

func (c *KMS) UpdateCustomKeyStore(input *UpdateCustomKeyStoreInput) (*UpdateCustomKeyStoreOutput, error)

UpdateCustomKeyStore API operation for AWS Key Management Service.

Changes the properties of a custom key store. Use the CustomKeyStoreId parameter to identify the custom key store you want to edit. Use the remaining parameters to change the properties of the custom key store.

You can only update a custom key store that is disconnected. To disconnect the custom key store, use DisconnectCustomKeyStore. To reconnect the custom key store after the update completes, use ConnectCustomKeyStore. To find the connection state of a custom key store, use the DescribeCustomKeyStores operation.

Use the NewCustomKeyStoreName parameter to change the friendly name of the custom key store to the value that you specify.

Use the KeyStorePassword parameter tell AWS KMS the current password of the kmsuser (https://docs.aws.amazon.com/kms/latest/developerguide/key-store-concepts.html#concept-kmsuser) crypto user (CU) in the associated AWS CloudHSM cluster. You can use this parameter to fix connection failures that occur when AWS KMS cannot log into the associated cluster because the kmsuser password has changed. This value does not change the password in the AWS CloudHSM cluster.

Use the CloudHsmClusterId parameter to associate the custom key store with a related AWS CloudHSM cluster, that is, a cluster that shares a backup history with the original cluster. You can use this parameter to repair a custom key store if its AWS CloudHSM cluster becomes corrupted or is deleted, or when you need to create or restore a cluster from a backup.

The cluster ID must identify a AWS CloudHSM cluster with the following requirements.

  • The cluster must be active and be in the same AWS account and Region as the custom key store.

  • The cluster must be configured with subnets in at least two different Availability Zones in the Region. Because AWS CloudHSM is not supported in all Availability Zones, we recommend that the cluster have subnets in all Availability Zones in the Region.

  • The cluster must contain at least two active HSMs, each in a different Availability Zone.

If the operation succeeds, it returns a JSON object with no properties.

This operation is part of the Custom Key Store feature (https://docs.aws.amazon.com/kms/latest/developerguide/custom-key-store-overview.html) feature in AWS KMS, which combines the convenience and extensive integration of AWS KMS with the isolation and control of a single-tenant key store.

Returns awserr.Error for service API and SDK errors. Use runtime type assertions with awserr.Error's Code and Message methods to get detailed information about the error.

See the AWS API reference guide for AWS Key Management Service's API operation UpdateCustomKeyStore for usage and error information.

Returned Error Codes:

  • ErrCodeCustomKeyStoreNotFoundException "CustomKeyStoreNotFoundException" The request was rejected because AWS KMS cannot find a custom key store with the specified key store name or ID.

  • ErrCodeCloudHsmClusterNotFoundException "CloudHsmClusterNotFoundException" The request was rejected because AWS KMS cannot find the AWS CloudHSM cluster with the specified cluster ID. Retry the request with a different cluster ID.

  • ErrCodeCloudHsmClusterNotRelatedException "CloudHsmClusterNotRelatedException" The request was rejected because the specified AWS CloudHSM cluster has a different cluster certificate than the original cluster. You cannot use the operation to specify an unrelated cluster.

Specify a cluster that shares a backup history with the original cluster. This includes clusters that were created from a backup of the current cluster, and clusters that were created from the same backup that produced the current cluster. Clusters that share a backup history have the same cluster certificate. To view the cluster certificate of a cluster, use the DescribeClusters (http://docs.aws.amazon.com/cloudhsm/latest/APIReference/API_DescribeClusters.html) operation.
  • ErrCodeCustomKeyStoreInvalidStateException "CustomKeyStoreInvalidStateException" The request was rejected because of the ConnectionState of the custom key store. To get the ConnectionState of a custom key store, use the DescribeCustomKeyStores operation.

This exception is thrown under the following conditions:
  • You requested the CreateKey or GenerateRandom operation in a custom key store that is not connected. These operations are valid only when the custom key store ConnectionState is CONNECTED.

  • You requested the UpdateCustomKeyStore or DeleteCustomKeyStore operation on a custom key store that is not disconnected. This operation is valid only when the custom key store ConnectionState is DISCONNECTED.

  • You requested the ConnectCustomKeyStore operation on a custom key store with a ConnectionState of DISCONNECTING or FAILED. This operation is valid for all other ConnectionState values.

  • ErrCodeInternalException "KMSInternalException" The request was rejected because an internal exception occurred. The request can be retried.

  • ErrCodeCloudHsmClusterNotActiveException "CloudHsmClusterNotActiveException" The request was rejected because the AWS CloudHSM cluster that is associated with the custom key store is not active. Initialize and activate the cluster and try the command again. For detailed instructions, see Getting Started

(http://docs.aws.amazon.com/cloudhsm/latest/userguide/getting-started.html) in the AWS CloudHSM User Guide.
  • ErrCodeCloudHsmClusterInvalidConfigurationException "CloudHsmClusterInvalidConfigurationException" The request was rejected because the associated AWS CloudHSM cluster did not meet the configuration requirements for a custom key store. The cluster must be configured with private subnets in at least two different Availability Zones in the Region. Also, it must contain at least as many HSMs as the operation requires.

For the CreateCustomKeyStore, UpdateCustomKeyStore, and CreateKey operations, the AWS CloudHSM cluster must have at least two active HSMs, each in a different Availability Zone. For the ConnectCustomKeyStore operation, the AWS CloudHSM must contain at least one active HSM. For information about creating a private subnet for a AWS CloudHSM cluster, see Create a Private Subnet (http://docs.aws.amazon.com/cloudhsm/latest/userguide/create-subnets.html) in the AWS CloudHSM User Guide. To add HSMs, use the AWS CloudHSM CreateHsm (http://docs.aws.amazon.com/cloudhsm/latest/APIReference/API_CreateHsm.html) operation.

See also, https://docs.aws.amazon.com/goto/WebAPI/kms-2014-11-01/UpdateCustomKeyStore

UpdateCustomKeyStoreRequest

func (c *KMS) UpdateCustomKeyStoreRequest(input *UpdateCustomKeyStoreInput) (req *request.Request, output *UpdateCustomKeyStoreOutput)

UpdateCustomKeyStoreRequest generates a "aws/request.Request" representing the client's request for the UpdateCustomKeyStore operation. The "output" return value will be populated with the request's response once the request completes successfully.

Use "Send" method on the returned Request to send the API call to the service. the "output" return value is not valid until after Send returns without error.

See UpdateCustomKeyStore for more information on using the UpdateCustomKeyStore API call, and error handling.

This method is useful when you want to inject custom logic or configuration into the SDK's request lifecycle. Such as custom headers, or retry logic.

// Example sending a request using the UpdateCustomKeyStoreRequest method. req, resp := client.UpdateCustomKeyStoreRequest(params) err := req.Send() if err == nil { // resp is now filled fmt.Println(resp) }

See also, https://docs.aws.amazon.com/goto/WebAPI/kms-2014-11-01/UpdateCustomKeyStore

UpdateCustomKeyStoreWithContext

func (c *KMS) UpdateCustomKeyStoreWithContext(ctx aws.Context, input *UpdateCustomKeyStoreInput, opts ...request.Option) (*UpdateCustomKeyStoreOutput, error)

UpdateCustomKeyStoreWithContext is the same as UpdateCustomKeyStore with the addition of the ability to pass a context and additional request options.

See UpdateCustomKeyStore for details on how to use this API operation.

The context must be non-nil and will be used for request cancellation. If the context is nil a panic will occur. In the future the SDK may create sub-contexts for http.Requests. See https://golang.org/pkg/context/ for more information on using Contexts.

See Also

For more information about using this API, see AWS API Documentation.

UpdateKeyDescription

func (c *KMS) UpdateKeyDescription(input *UpdateKeyDescriptionInput) (*UpdateKeyDescriptionOutput, error)

UpdateKeyDescription API operation for AWS Key Management Service.

Updates the description of a customer master key (CMK). To see the decription of a CMK, use DescribeKey.

You cannot perform this operation on a CMK in a different AWS account.

The result of this operation varies with the key state of the CMK. For details, see How Key State Affects Use of a Customer Master Key (https://docs.aws.amazon.com/kms/latest/developerguide/key-state.html) in the AWS Key Management Service Developer Guide.

Returns awserr.Error for service API and SDK errors. Use runtime type assertions with awserr.Error's Code and Message methods to get detailed information about the error.

See the AWS API reference guide for AWS Key Management Service's API operation UpdateKeyDescription for usage and error information.

Returned Error Codes:

  • ErrCodeNotFoundException "NotFoundException" The request was rejected because the specified entity or resource could not be found.

  • ErrCodeInvalidArnException "InvalidArnException" The request was rejected because a specified ARN was not valid.

  • ErrCodeDependencyTimeoutException "DependencyTimeoutException" The system timed out while trying to fulfill the request. The request can be retried.

  • ErrCodeInternalException "KMSInternalException" The request was rejected because an internal exception occurred. The request can be retried.

  • ErrCodeInvalidStateException "KMSInvalidStateException" The request was rejected because the state of the specified resource is not valid for this request.

For more information about how key state affects the use of a CMK, see How Key State Affects Use of a Customer Master Key (http://docs.aws.amazon.com/kms/latest/developerguide/key-state.html) in the AWS Key Management Service Developer Guide.

See also, https://docs.aws.amazon.com/goto/WebAPI/kms-2014-11-01/UpdateKeyDescription

Example

KMS UpdateKeyDescription shared00

To update the description of a customer master key (CMK)

The following example updates the description of the specified CMK.

{ svc := kms.New(session.New()) input := &kms.UpdateKeyDescriptionInput{ Description: aws.String("Example description that indicates the intended use of this CMK."), KeyId: aws.String("1234abcd-12ab-34cd-56ef-1234567890ab"), } result, err := svc.UpdateKeyDescription(input) if err != nil { if aerr, ok := err.(awserr.Error); ok { switch aerr.Code() { case kms.ErrCodeNotFoundException: fmt.Println(kms.ErrCodeNotFoundException, aerr.Error()) case kms.ErrCodeInvalidArnException: fmt.Println(kms.ErrCodeInvalidArnException, aerr.Error()) case kms.ErrCodeDependencyTimeoutException: fmt.Println(kms.ErrCodeDependencyTimeoutException, aerr.Error()) case kms.ErrCodeInternalException: fmt.Println(kms.ErrCodeInternalException, aerr.Error()) case kms.ErrCodeInvalidStateException: fmt.Println(kms.ErrCodeInvalidStateException, aerr.Error()) default: fmt.Println(aerr.Error()) } } else { fmt.Println(err.Error()) } return } fmt.Println(result) }

UpdateKeyDescriptionRequest

func (c *KMS) UpdateKeyDescriptionRequest(input *UpdateKeyDescriptionInput) (req *request.Request, output *UpdateKeyDescriptionOutput)

UpdateKeyDescriptionRequest generates a "aws/request.Request" representing the client's request for the UpdateKeyDescription operation. The "output" return value will be populated with the request's response once the request completes successfully.

Use "Send" method on the returned Request to send the API call to the service. the "output" return value is not valid until after Send returns without error.

See UpdateKeyDescription for more information on using the UpdateKeyDescription API call, and error handling.

This method is useful when you want to inject custom logic or configuration into the SDK's request lifecycle. Such as custom headers, or retry logic.

// Example sending a request using the UpdateKeyDescriptionRequest method. req, resp := client.UpdateKeyDescriptionRequest(params) err := req.Send() if err == nil { // resp is now filled fmt.Println(resp) }

See also, https://docs.aws.amazon.com/goto/WebAPI/kms-2014-11-01/UpdateKeyDescription

UpdateKeyDescriptionWithContext

func (c *KMS) UpdateKeyDescriptionWithContext(ctx aws.Context, input *UpdateKeyDescriptionInput, opts ...request.Option) (*UpdateKeyDescriptionOutput, error)

UpdateKeyDescriptionWithContext is the same as UpdateKeyDescription with the addition of the ability to pass a context and additional request options.

See UpdateKeyDescription for details on how to use this API operation.

The context must be non-nil and will be used for request cancellation. If the context is nil a panic will occur. In the future the SDK may create sub-contexts for http.Requests. See https://golang.org/pkg/context/ for more information on using Contexts.

See Also

For more information about using this API, see AWS API Documentation.

On this page: