IAM ユーザーのユーザーアクセスキーを作成する - AWS SDK for Ruby

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

IAM ユーザーのユーザーアクセスキーを作成する

以下の例では、us-west-2 リージョンで IAM ユーザー my_groovy_user のアクセスキーとシークレットキーを作成します。

# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # SPDX - License - Identifier: Apache - 2.0 require 'aws-sdk-iam' # Creates an access key for a user in AWS Identity and Access Management (IAM). # # Prerequisites: # - The user in IAM. # # @param iam [Aws::IAM::Client] An initialized IAM client. # @param user_name [String] The name of the user. # @example # create_access_key(Aws::IAM::Client.new, 'my-user') def create_access_key(iam, user_name) response = iam.create_access_key(user_name: user_name) access_key = response.access_key puts 'Access key created:' puts " Access key ID: #{access_key.access_key_id}" puts " Secret access key: #{access_key.secret_access_key}" puts 'Keep a record of this information in a secure location. ' \ 'This will be the only time you will be able to view the ' \ 'secret access key.' rescue Aws::IAM::Errors::LimitExceeded puts 'Error creating access key: limit exceeded. Cannot create any more. ' \ 'To create more, delete an existing access key, and then try again.' rescue StandardError => e puts "Error creating access key: #{e.message}" end # Full example call: def run_me iam = Aws::IAM::Client.new user_name = 'my-user' puts 'Attempting to create an access key...' create_access_key(iam, user_name) end run_me if $PROGRAM_NAME == __FILE__