本文整理汇总了Golang中github.com/aws/aws-sdk-go/service/iam.IAM.AttachRolePolicy方法的典型用法代码示例。如果您正苦于以下问题:Golang IAM.AttachRolePolicy方法的具体用法?Golang IAM.AttachRolePolicy怎么用?Golang IAM.AttachRolePolicy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/aws/aws-sdk-go/service/iam.IAM
的用法示例。
在下文中一共展示了IAM.AttachRolePolicy方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: attachPolicyToRole
func attachPolicyToRole(conn *iam.IAM, role string, arn string) error {
_, err := conn.AttachRolePolicy(&iam.AttachRolePolicyInput{
RoleName: aws.String(role),
PolicyArn: aws.String(arn),
})
if err != nil {
return err
}
return nil
}
示例2: attachPolicyToRoles
func attachPolicyToRoles(conn *iam.IAM, roles []*string, arn string) error {
for _, r := range roles {
_, err := conn.AttachRolePolicy(&iam.AttachRolePolicyInput{
RoleName: r,
PolicyArn: aws.String(arn),
})
if err != nil {
return err
}
}
return nil
}
示例3: attachPolicyToRoles
func attachPolicyToRoles(conn *iam.IAM, roles []*string, arn string) error {
for _, r := range roles {
_, err := conn.AttachRolePolicy(&iam.AttachRolePolicyInput{
RoleName: r,
PolicyArn: aws.String(arn),
})
if err != nil {
return err
}
var attachmentErr error
attachmentErr = resource.Retry(2*time.Minute, func() *resource.RetryError {
input := iam.ListRolePoliciesInput{
RoleName: r,
}
attachedPolicies, err := conn.ListRolePolicies(&input)
if err != nil {
return resource.NonRetryableError(err)
}
if len(attachedPolicies.PolicyNames) > 0 {
var foundPolicy bool
for _, policyName := range attachedPolicies.PolicyNames {
if strings.HasSuffix(arn, *policyName) {
foundPolicy = true
break
}
}
if !foundPolicy {
return resource.NonRetryableError(err)
}
}
return nil
})
if attachmentErr != nil {
return attachmentErr
}
}
return nil
}