Showing posts with label command line. Show all posts
Showing posts with label command line. Show all posts

How to create AWS instance profile via command line?

1)Create instance profile
aws iam create-instance-profile

2)Attach role to instance profile
aws iam add-role-to-instance-profile

# Create the role and attach the trust policy that enables EC2 to assume this role.
aws iam create-role --role-name Test-Role-for-EC2 --assume-role-policy-document file://C:\policies\trustpolicyforec2.json

# Embed the permissions policy (in this example an inline policy) to the role to specify what it is allowed to do.
aws iam put-role-policy --role-name Test-Role-for-EC2 --policy-name Permissions-Policy-For-Ec2 --policy-document file://c:\policies\permissionspolicyforec2.json

# Create the instance profile required by EC2 to contain the role
aws iam create-instance-profile --instance-profile-name EC2-ListBucket-S3

# Finally, add the role to the instance profile
aws iam add-role-to-instance-profile --instance-profile-name EC2-ListBucket-S3 --role-name Test-Role-for-EC2

Create role for AWS service via command line

1)Create role
aws iam create-role

2)attch policy to role

2.1)Attach managed poilicy to role
aws iam attach-role-plicy

or
2.2)Attach inline policy
aws iam put-role-plicy