使用 Amazon 开发工具包获取 IAM 账户密码策略
以下代码示例显示如何获取 IAM 账户密码策略。
- .NET
-
- Amazon SDK for .NET
-
注意
在 GitHub 上查看更多内容。查找完整示例,学习如何在 Amazon 代码示例存储库
中进行设置和运行。 /// <summary> /// Gets the IAM password policy for an AWS account. /// </summary> /// <returns>The PasswordPolicy for the AWS account.</returns> public async Task<PasswordPolicy> GetAccountPasswordPolicyAsync() { var response = await _IAMService.GetAccountPasswordPolicyAsync(new GetAccountPasswordPolicyRequest()); return response.PasswordPolicy; }-
有关 API 详细信息,请参阅《Amazon SDK for .NET API 参考》中的 GetAccountPasswordPolicy。
-
- Go
-
- SDK for Go V2
-
注意
在 GitHub 上查看更多内容。查找完整示例,学习如何在 Amazon 代码示例存储库
中进行设置和运行。 // AccountWrapper encapsulates AWS Identity and Access Management (IAM) account actions // used in the examples. // It contains an IAM service client that is used to perform account actions. type AccountWrapper struct { IamClient *iam.Client } // GetAccountPasswordPolicy gets the account password policy for the current account. // If no policy has been set, a NoSuchEntityException is error is returned. func (wrapper AccountWrapper) GetAccountPasswordPolicy() (*types.PasswordPolicy, error) { var pwPolicy *types.PasswordPolicy result, err := wrapper.IamClient.GetAccountPasswordPolicy(context.TODO(), &iam.GetAccountPasswordPolicyInput{}) if err != nil { log.Printf("Couldn't get account password policy. Here's why: %v\n", err) } else { pwPolicy = result.PasswordPolicy } return pwPolicy, err }-
有关 API 详细信息,请参阅《Amazon SDK for Go API 参考》中的 GetAccountPasswordPolicy
。
-
- JavaScript
-
- SDK for JavaScript (v3)
-
注意
在 GitHub 上查看更多内容。在 Amazon 代码示例存储库
中查找完整示例,了解如何进行设置和运行。 获取账户密码策略。
import { GetAccountPasswordPolicyCommand, IAMClient, } from "@aws-sdk/client-iam"; const client = new IAMClient({}); export const getAccountPasswordPolicy = async () => { const command = new GetAccountPasswordPolicyCommand({}); const response = await client.send(command); console.log(response.PasswordPolicy); return response; };-
有关 API 详细信息,请参阅《Amazon SDK for JavaScript API 参考》中的 GetAccountPasswordPolicy。
-
- PHP
-
- SDK for PHP
-
注意
在 GitHub 上查看更多内容。查找完整示例,学习如何在 Amazon 代码示例存储库
中进行设置和运行。 $uuid = uniqid(); $service = new IAMService(); public function getAccountPasswordPolicy() { return $this->iamClient->getAccountPasswordPolicy(); }-
有关 API 详细信息,请参阅《Amazon SDK for PHP API 参考》中的 GetAccountPasswordPolicy。
-
- Python
-
- 适用于 Python (Boto3) 的 SDK
-
注意
在 GitHub 上查看更多内容。在 Amazon 代码示例存储库
中查找完整示例,了解如何进行设置和运行。 def print_password_policy(): """ Prints the password policy for the account. """ try: pw_policy = iam.AccountPasswordPolicy() print("Current account password policy:") print(f"\tallow_users_to_change_password: {pw_policy.allow_users_to_change_password}") print(f"\texpire_passwords: {pw_policy.expire_passwords}") print(f"\thard_expiry: {pw_policy.hard_expiry}") print(f"\tmax_password_age: {pw_policy.max_password_age}") print(f"\tminimum_password_length: {pw_policy.minimum_password_length}") print(f"\tpassword_reuse_prevention: {pw_policy.password_reuse_prevention}") print(f"\trequire_lowercase_characters: {pw_policy.require_lowercase_characters}") print(f"\trequire_numbers: {pw_policy.require_numbers}") print(f"\trequire_symbols: {pw_policy.require_symbols}") print(f"\trequire_uppercase_characters: {pw_policy.require_uppercase_characters}") printed = True except ClientError as error: if error.response['Error']['Code'] == 'NoSuchEntity': print("The account does not have a password policy set.") else: logger.exception("Couldn't get account password policy.") raise else: return printed-
有关 API 详细信息,请参阅《Amazon SDK for Python(Boto3)API 参考》中的 GetAccountPasswordPolicy。
-
- Ruby
-
- SDK for Ruby
-
注意
在 GitHub 上查看更多内容。查找完整示例,学习如何在 Amazon 代码示例存储库
中进行设置和运行。 # Prints the password policy for the account. def print_account_password_policy policy = @iam_resource.account_password_policy policy.load puts("The account password policy is:") puts(policy.data.to_h) rescue Aws::Errors::ServiceError => e if e.code == "NoSuchEntity" puts("The account does not have a password policy.") else puts("Couldn't print the account password policy. Here's why:") puts("\t#{e.code}: #{e.message}") raise end end-
有关 API 详细信息,请参阅《Amazon SDK for Ruby API 参考》中的 GetAccountPasswordPolicy。
-
- Rust
-
- SDK for Rust
-
注意
本文档适用于预览版中的软件开发工具包。软件开发工具包可能随时发生变化,不应在生产环境中使用。
注意
在 GitHub 上查看更多内容。查找完整示例,学习如何在 Amazon 代码示例存储库
中进行设置和运行。 pub async fn get_account_password_policy( client: &iamClient, ) -> Result<GetAccountPasswordPolicyOutput, SdkError<GetAccountPasswordPolicyError>> { let response = client.get_account_password_policy().send().await?; Ok(response) }-
有关 API 详细信息,请参阅《Amazon SDK for Rust API 参考》中的 GetAccountPasswordPolicy
。
-
有关 Amazon 软件开发工具包开发人员指南和代码示例的完整列表,请参阅 将 IAM 与 Amazon 开发工具包配合使用。本主题还包括有关入门的信息以及有关先前的软件开发工具包版本的详细信息。