GuidesAPI
DocumentationAPICommunitySupportLog In

Attaching an IAM Role to a EC2 Instance

To configure access to the S3 bucket from your EC2 using IAM roles, attach an IAM role to your instance, to be used for authentication, as described in the link below. This step allows your EC2 instance to write and retrieve data from the S3 bucket:
https://aws.amazon.com/blogs/security/easily-replace-or-attach-an-iam-role-to-an-existing-ec2-instance-by-using-the-ec2-console/

Example for using IAM Role:

{
    "Version": "2008-10-17",
    "Id": "Policy1388257451238",
    "Statement": [
        {
            "Sid": "1232343455",
            "Effect": "Allow",
            "Principal": {
                "AWS": "arn:aws:iam::432746435694:role/custom-role"
            },
            "Action": [
                "s3:GetObject",
                "s3:PutObject"
            ],
            "Resource": "arn:aws:s3:::hybridtest/*"
        }
    ] 
}

the IAM role: "arn:aws:iam::432746435694:role/custom-role"
the S3 Bucket arn: "arn:aws:s3:::hybridtest/*"