I have created an AWS role and attached a policy to put objects in a S3 bucket.
I have a local Python application which is using the role. My personal AWS user has the permission to assume a role. Here is some code I use:
assumed_role_object = sts_client.assume_role(
RoleArn="arn:aws:iam::account-id:role/test-role",
RoleSessionName="myRoleSession"
)
This is working all fine but now my question is how I have to configure this on my on-premise server where I don't configure my personal user to assume the role.
I was thinking about creating an IAM user which has only the assumeRole permission and use this user to assume a role for my application.
I use a test-role-trust-policy.json
{
"Version": "2012-10-17",
"Statement": {
"Effect": "Allow",
"Principal": { "AWS": "arn:aws:iam::123456789012:root" },
"Action": "sts:AssumeRole"
}
}
and create the role with this:
aws iam create-role --role-name test-role --assume-role-policy-document file://test-role-trust-policy.json
Attach the necessary policies to my role (to put the S3 objects) and use the role in my application.
Is this the correct approach to configure a role for an on-premise server? I find it strange to create a user to use a role on my on-premise server (although the permission of the user is now restricted).
It's also not very clear for me if I have to use the root as principal or my user?