This can be done using IAM roles. IAM roles are attached to the AWS resources like EC2, Lambda, RedShift to give the proper permissions. Here are the sequence of steps for the same.
- Create a policy to give Read and Write Permissions to a specific S3 Bucket or use the existing AmazonS3FullAccess policy.
- Create an IAM role and attach the one of the above policies.
- Attach the role to the EC2 instance.
Depending upon the policy attached to the role, the EC2 would be getting the appropriate permissions. In this case, the application running on EC2 would be able to upload/ download the images from S3.