The WordPress instances need an IAM role with three kinds of permissions:
rds!*): lets the instance read the database user name and password when WordPress is configured.The lab account requires every IAM role name to start with FCJ- and to use the permissions boundary LabPermissionsBoundary. If your own account has no permissions boundary, remove the --permissions-boundary line.
In AWS CloudShell, run the following commands. Replace the bucket name with your own:
ACCOUNT=$(aws sts get-caller-identity --query Account --output text)
BUCKET=fcj-wordpress-files-1795416336
R=FCJ-WordPress-EC2-Role
aws iam create-role --role-name $R \
--permissions-boundary arn:aws:iam::$ACCOUNT:policy/LabPermissionsBoundary \
--assume-role-policy-document '{"Version":"2012-10-17","Statement":[{"Effect":"Allow","Principal":{"Service":"ec2.amazonaws.com"},"Action":"sts:AssumeRole"}]}' \
--query Role.RoleName --output text
aws iam attach-role-policy --role-name $R --policy-arn arn:aws:iam::aws:policy/AmazonSSMManagedInstanceCore
aws iam put-role-policy --role-name $R --policy-name WordPressAppAccess --policy-document '{
"Version": "2012-10-17",
"Statement": [
{"Effect": "Allow", "Action": "secretsmanager:GetSecretValue",
"Resource": "arn:aws:secretsmanager:ap-northeast-1:'$ACCOUNT':secret:rds!*"},
{"Effect": "Allow", "Action": "rds:DescribeDBInstances", "Resource": "*"},
{"Effect": "Allow", "Action": "s3:GetObject", "Resource": "arn:aws:s3:::'$BUCKET'/*"}
]}'
aws iam create-instance-profile --instance-profile-name $R --query InstanceProfile.InstanceProfileName --output text
aws iam add-role-to-instance-profile --instance-profile-name $R --role-name $R && echo ROLE-OK
The output ends with ROLE-OK. Open the IAM console → Roles → (1) FCJ-WordPress-EC2-Role. The (2) Permissions tab shows the AWS managed policy and the inline policy WordPressAppAccess.
