Creates a new Amazon Web Services secret access key and corresponding Amazon Web Services access key ID for the specified user. The default status for new keys is Active.
If you do not specify a user name, IAM determines the user name implicitly based on the Amazon Web Services access key ID signing the request. This operation works for access keys under the Amazon Web Services account. Consequently, you can use this operation to manage Amazon Web Services account root user credentials. This is true even if the Amazon Web Services account has no associated users.
For information about quotas on the number of keys you can create, see IAM and STS quotas in the IAM User Guide.
To ensure the security of your Amazon Web Services account, the secret access key is accessible only during key and user creation. You must save the key (for example, in a text file) if you want to be able to access it again. If a secret key is lost, you can delete the access keys for the associated user and then create new keys.
Parameters:
-
user_name
(Optional[existingUserNameType], default:
None
)
–
The name of the IAM user that the new key will belong to.
This parameter allows (through its regex pattern) a string of characters consisting of upper and lowercase alphanumeric characters with no spaces. You can also include any of the following characters: _+=,.@-
Raises:
-
LimitExceededException
–
The request was rejected because it attempted to create resources beyond the current Amazon Web Services account limits. The error message describes the limit exceeded.
-
NoSuchEntityException
–
The request was rejected because it referenced a resource entity that does not exist. The error message describes the resource.
-
ServiceFailureException
–
The request processing has failed because of an unknown error, exception or failure.
-
UnknownServiceError
–
The service returned an error code this client does not model.
Examples:
To create an access key for an IAM user
The following command creates an access key (access key ID and secret access key) for the IAM user named Bob.
>>> await client.create_access_key(user_name='Bob')
Source code in docs_src/capo_iam/_services/async_iam.py
| async def create_access_key(
self,
*,
config_overrides: Optional[AsyncIAMClientConfig] = None,
user_name: Optional[
"capo_iam.types.existing_user_name_type.existingUserNameType"
] = None,
) -> "capo_iam.types.create_access_key_response.CreateAccessKeyResponse":
"""<p> Creates a new Amazon Web Services secret access key and corresponding Amazon Web Services access key ID for the specified user. The default status for new keys is <code>Active</code>.</p> <p>If you do not specify a user name, IAM determines the user name implicitly based on the Amazon Web Services access key ID signing the request. This operation works for access keys under the Amazon Web Services account. Consequently, you can use this operation to manage Amazon Web Services account root user credentials. This is true even if the Amazon Web Services account has no associated users.</p> <p> For information about quotas on the number of keys you can create, see <a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_iam-quotas.html">IAM and STS quotas</a> in the <i>IAM User Guide</i>.</p> <important> <p>To ensure the security of your Amazon Web Services account, the secret access key is accessible only during key and user creation. You must save the key (for example, in a text file) if you want to be able to access it again. If a secret key is lost, you can delete the access keys for the associated user and then create new keys.</p> </important>
Args:
user_name: <p>The name of the IAM user that the new key will belong to.</p> <p>This parameter allows (through its <a href="http://wikipedia.org/wiki/regex">regex pattern</a>) a string of characters consisting of upper and lowercase alphanumeric characters with no spaces. You can also include any of the following characters: _+=,.@-</p>
Raises:
capo_iam.errors.limit_exceeded_exception.LimitExceededException: <p>The request was rejected because it attempted to create resources beyond the current Amazon Web Services account limits. The error message describes the limit exceeded.</p>
capo_iam.errors.no_such_entity_exception.NoSuchEntityException: <p>The request was rejected because it referenced a resource entity that does not exist. The error message describes the resource.</p>
capo_iam.errors.service_failure_exception.ServiceFailureException: <p>The request processing has failed because of an unknown error, exception or failure.</p>
capo_iam.errors.UnknownServiceError: The service returned an error code this client does not model.
Examples:
To create an access key for an IAM user
The following command creates an access key (access key ID and secret access key) for the IAM user named Bob.
>>> await client.create_access_key(user_name='Bob')
"""
async def _handler(
req: "AsyncOperationRequest[capo_iam.types.create_access_key_request.CreateAccessKeyRequest]",
) -> AsyncOperationResponse[
"capo_iam.types.create_access_key_response.CreateAccessKeyResponse"
]:
import capo_iam._operations.aws_identity_management_v20100508.create_access_key
(
output,
http_response,
) = await capo_iam._operations.aws_identity_management_v20100508.create_access_key.async_create_access_key(
req.options, req.input
)
return AsyncOperationResponse(output=output, response=http_response)
def _redact_output(
output: "capo_iam.types.create_access_key_response.CreateAccessKeyResponse",
) -> dict[str, Any]:
import capo_iam.types.create_access_key_response
return capo_iam.types.create_access_key_response.redact_sensitive(output)
interceptors_, options_ = self.operation_options(
config_overrides,
OperationLogging("CreateAccessKey", redact_output=_redact_output),
)
input_: capo_iam.types.create_access_key_request.CreateAccessKeyRequest = {}
if user_name is not None:
input_["user_name"] = user_name
response = await aexecute_pipeline(
AsyncOperationRequest(input=input_, options=options_),
handler=_handler,
interceptors=list(interceptors_),
)
await response.response.aclose()
return response.output
|