PolicyAttachment
The PolicyAttachment resource lets you attach AWS IAM policies to IAM roles.
Minimal Example
Section titled “Minimal Example”Attach an AWS managed policy to a role:
import { PolicyAttachment } from "alchemy/aws";
const adminAccess = await PolicyAttachment("admin-policy", { policyArn: "arn:aws:iam::aws:policy/AdministratorAccess", roleName: role.name,});
Attach Custom Policy
Section titled “Attach Custom Policy”Attach a custom policy created with the Policy resource:
import { PolicyAttachment } from "alchemy/aws";
const customPolicy = await PolicyAttachment("custom-policy", { policyArn: policy.arn, roleName: role.name,});
Multiple Policy Attachments
Section titled “Multiple Policy Attachments”Attach multiple policies to a role:
import { PolicyAttachment } from "alchemy/aws";
const s3Access = await PolicyAttachment("s3-access", { policyArn: "arn:aws:iam::aws:policy/AmazonS3FullAccess", roleName: role.name,});
const sqsAccess = await PolicyAttachment("sqs-access", { policyArn: "arn:aws:iam::aws:policy/AmazonSQSFullAccess", roleName: role.name,});