ruby/example_code/iam/iam-ruby-example-manage-policies.rb
# Creates a policy in AWS Identity and Access Management (IAM).
#
# @param iam_client [Aws::IAM::Client] An initialized IAM client.
# @param policy_name [String] A name for the policy.
# @param policy_document [Hash] The policy definition.
# @return [String] The new policy's Amazon Resource Name (ARN);
#   otherwise, the string 'Error'.
# @example
#   puts create_policy(
#     Aws::IAM::Client.new,
#     'my-policy',
#     {
#       'Version': '2012-10-17',
#       'Statement': [
#         {
#           'Effect': 'Allow',
#           'Action': 's3:ListAllMyBuckets',
#           'Resource': 'arn:aws:s3:::*'
#         }
#       ]
#     }
#   )

Creates a policy in AWS Identity and Access Management (IAM).
Creates a policy in AWS Identity and Access Management ( IAM ) .
def create_policy(iam_client, policy_name, policy_document)
  response = iam_client.create_policy(
    policy_name: policy_name,
    policy_document: policy_document.to_json
  )
  return response.policy.arn
rescue StandardError => e
  puts "Error creating policy: #{e.message}"
  return 'Error'
end
def create_policy ( iam_client , policy_name , policy_document ) response = iam_client . create_policy ( policy_name : policy_name , policy_document : policy_document . to_json ) return response . policy . arn rescue StandardError => e puts "Error creating policy: #{e.message}" return 'Error' end
Creates a policy in AWS Identity and Access Management (IAM).
Creates a policy in AWS Identity and Access Management ( IAM ) .
The new policy's Amazon Resource Name (ARN); otherwise, the string 'Error'.
The new policy ' s Amazon Resource Name ( ARN ) ; otherwise the string ' Error ' .
String
iam_client
An initialized IAM client.
An initialized IAM client .
policy_name
A name for the policy.
A name for the policy .
policy_document
The policy definition.
The policy definition .
example
None