Skip to main content
In this tutorial, you’ll grant the IAM user John temporary file-upload permissions to the S3 bucket company1-hr using an AWS STS session policy and a dedicated IAM role. By the end, John will be able to upload objects for a limited time without altering his long-term permissions.

Prerequisites

  • AWS CLI installed and configured for user John
  • Bucket company1-hr already exists in account 629470240201
  • Basic familiarity with IAM, STS, and S3 permissions

Step 1: Verify Current AWS Identity

Confirm you’re authenticated as John:
Expected output:

Step 2: List Bucket Contents and Test Upload

Check existing objects and verify that upload is currently denied:

Step 3: Define the Session Policy

Create a JSON policy that allows listing, reading, and uploading:
Save this policy as SessionPolicy-UploadFile.json and upload it as a customer-managed policy named SessionPolicy-UploadFile.

Step 4: Create and Configure the IAM Role

  1. In the IAM console or via AWS CLI, create a role JohnUploadRole.
  2. Attach the SessionPolicy-UploadFile policy to this role.
Update the role’s trust policy so that John can assume it:
Ensure the trust relationship is properly updated—otherwise, John will not be able to assume the role.

Step 5: Assume the Role and Export Temporary Credentials

Have John run the following to get short-lived credentials:
Sample response:
Export these values to the environment:

Step 6: Verify Upload Succeeds

With the new session credentials, repeat the list and upload:
The file new-file.txt is now uploaded. These permissions automatically expire when the session token’s Expiration time is reached.

Watch Video