1// Code generated by smithy-go-codegen DO NOT EDIT.
2
3package kms
4
5import (
6	"context"
7	awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware"
8	"github.com/aws/aws-sdk-go-v2/aws/signer/v4"
9	"github.com/aws/smithy-go/middleware"
10	smithyhttp "github.com/aws/smithy-go/transport/http"
11)
12
13// Creates a friendly name for a customer master key (CMK). You can use an alias to
14// identify a CMK in the AWS KMS console, in the DescribeKey operation and in
15// cryptographic operations
16// (https://docs.aws.amazon.com/kms/latest/developerguide/concepts.html#cryptographic-operations),
17// such as Encrypt and GenerateDataKey. You can also change the CMK that's
18// associated with the alias (UpdateAlias) or delete the alias (DeleteAlias) at any
19// time. These operations don't affect the underlying CMK. You can associate the
20// alias with any customer managed CMK in the same AWS Region. Each alias is
21// associated with only on CMK at a time, but a CMK can have multiple aliases. A
22// valid CMK is required. You can't create an alias without a CMK. The alias must
23// be unique in the account and Region, but you can have aliases with the same name
24// in different Regions. For detailed information about aliases, see Using aliases
25// (https://docs.aws.amazon.com/kms/latest/developerguide/kms-alias.html) in the
26// AWS Key Management Service Developer Guide. This operation does not return a
27// response. To get the alias that you created, use the ListAliases operation. The
28// CMK that you use for this operation must be in a compatible key state. For
29// details, see How Key State Affects Use of a Customer Master Key
30// (https://docs.aws.amazon.com/kms/latest/developerguide/key-state.html) in the
31// AWS Key Management Service Developer Guide. Cross-account use: No. You cannot
32// perform this operation on an alias in a different AWS account. Required
33// permissions
34//
35// * kms:CreateAlias
36// (https://docs.aws.amazon.com/kms/latest/developerguide/kms-api-permissions-reference.html)
37// on the alias (IAM policy).
38//
39// * kms:CreateAlias
40// (https://docs.aws.amazon.com/kms/latest/developerguide/kms-api-permissions-reference.html)
41// on the CMK (key policy).
42//
43// For details, see Controlling access to aliases
44// (https://docs.aws.amazon.com/kms/latest/developerguide/kms-alias.html#alias-access)
45// in the AWS Key Management Service Developer Guide. Related operations:
46//
47// *
48// DeleteAlias
49//
50// * ListAliases
51//
52// * UpdateAlias
53func (c *Client) CreateAlias(ctx context.Context, params *CreateAliasInput, optFns ...func(*Options)) (*CreateAliasOutput, error) {
54	if params == nil {
55		params = &CreateAliasInput{}
56	}
57
58	result, metadata, err := c.invokeOperation(ctx, "CreateAlias", params, optFns, addOperationCreateAliasMiddlewares)
59	if err != nil {
60		return nil, err
61	}
62
63	out := result.(*CreateAliasOutput)
64	out.ResultMetadata = metadata
65	return out, nil
66}
67
68type CreateAliasInput struct {
69
70	// Specifies the alias name. This value must begin with alias/ followed by a name,
71	// such as alias/ExampleAlias. The AliasName value must be string of 1-256
72	// characters. It can contain only alphanumeric characters, forward slashes (/),
73	// underscores (_), and dashes (-). The alias name cannot begin with alias/aws/.
74	// The alias/aws/ prefix is reserved for AWS managed CMKs
75	// (https://docs.aws.amazon.com/kms/latest/developerguide/concepts.html#aws-managed-cmk).
76	//
77	// This member is required.
78	AliasName *string
79
80	// Associates the alias with the specified customer managed CMK
81	// (https://docs.aws.amazon.com/kms/latest/developerguide/concepts.html#customer-cmk).
82	// The CMK must be in the same AWS Region. A valid CMK ID is required. If you
83	// supply a null or empty string value, this operation returns an error. For help
84	// finding the key ID and ARN, see Finding the Key ID and ARN
85	// (https://docs.aws.amazon.com/kms/latest/developerguide/viewing-keys.html#find-cmk-id-arn)
86	// in the AWS Key Management Service Developer Guide. Specify the key ID or the
87	// Amazon Resource Name (ARN) of the CMK. For example:
88	//
89	// * Key ID:
90	// 1234abcd-12ab-34cd-56ef-1234567890ab
91	//
92	// * Key ARN:
93	// arn:aws:kms:us-east-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab
94	//
95	// To
96	// get the key ID and key ARN for a CMK, use ListKeys or DescribeKey.
97	//
98	// This member is required.
99	TargetKeyId *string
100}
101
102type CreateAliasOutput struct {
103	// Metadata pertaining to the operation's result.
104	ResultMetadata middleware.Metadata
105}
106
107func addOperationCreateAliasMiddlewares(stack *middleware.Stack, options Options) (err error) {
108	err = stack.Serialize.Add(&awsAwsjson11_serializeOpCreateAlias{}, middleware.After)
109	if err != nil {
110		return err
111	}
112	err = stack.Deserialize.Add(&awsAwsjson11_deserializeOpCreateAlias{}, middleware.After)
113	if err != nil {
114		return err
115	}
116	if err = addSetLoggerMiddleware(stack, options); err != nil {
117		return err
118	}
119	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
120		return err
121	}
122	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
123		return err
124	}
125	if err = addResolveEndpointMiddleware(stack, options); err != nil {
126		return err
127	}
128	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
129		return err
130	}
131	if err = addRetryMiddlewares(stack, options); err != nil {
132		return err
133	}
134	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
135		return err
136	}
137	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
138		return err
139	}
140	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
141		return err
142	}
143	if err = addClientUserAgent(stack); err != nil {
144		return err
145	}
146	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
147		return err
148	}
149	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
150		return err
151	}
152	if err = addOpCreateAliasValidationMiddleware(stack); err != nil {
153		return err
154	}
155	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opCreateAlias(options.Region), middleware.Before); err != nil {
156		return err
157	}
158	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
159		return err
160	}
161	if err = addResponseErrorMiddleware(stack); err != nil {
162		return err
163	}
164	if err = addRequestResponseLogging(stack, options); err != nil {
165		return err
166	}
167	return nil
168}
169
170func newServiceMetadataMiddleware_opCreateAlias(region string) *awsmiddleware.RegisterServiceMetadata {
171	return &awsmiddleware.RegisterServiceMetadata{
172		Region:        region,
173		ServiceID:     ServiceID,
174		SigningName:   "kms",
175		OperationName: "CreateAlias",
176	}
177}
178