AWS SDK for Ruby
Developer Guide

Adding a Managed Policy to an IAM User

The following example adds the managed policy AmazonS3FullAccess to the IAM user my_groovy_user in the us-west-2 region.

require 'aws-sdk-iam' # v2: require 'aws-sdk' # Policy ARNs start with: prefix = 'arn:aws:iam::aws:policy/' policy_arn = prefix + 'AmazonS3FullAccess' # In case the policy or user does not exist begin client.attach_user_policy({user_name: 'my_groovy_user', policy_arn: policy_arn}) rescue Aws::IAM::Errors::NoSuchEntity => ex puts "Error attaching policy '#{policy_arn}'" puts ex.message end