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-hralready exists in account629470240201 - Basic familiarity with IAM, STS, and S3 permissions
Step 1: Verify Current AWS Identity
Confirm you’re authenticated as John: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:| Action | Description |
|---|---|
| s3:ListBucket | List the bucket’s objects |
| s3:GetObject | Download or read bucket objects |
| s3:PutObject | Upload new objects to the bucket |
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
- In the IAM console or via AWS CLI, create a role JohnUploadRole.
- Attach the
SessionPolicy-UploadFilepolicy to this role.
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:Step 6: Verify Upload Succeeds
With the new session credentials, repeat the list and upload:new-file.txt is now uploaded. These permissions automatically expire when the session token’s Expiration time is reached.