Demonstrate uploading a file to an S3 storage bucket using the AWS SDK for Java.
-
Create an S3 bucket:
aws s3api create-bucket --bucket <bucket-name> --region <region>
-
Create an IAM Identity Center user:
aws iam create-user --user-name <user-name> --profile <profile-name>
-
Attach the
AmazonS3FullAccess
policy to the user:aws iam attach-user-policy --policy-arn arn:aws:iam::aws:policy/AmazonS3FullAccess --user-name <user-name> --profile <profile-name>
- Sign in to the AWS Management Console.
- Open the IAM Identity Center.
- In the IAM Identity Center dashboard, select "Permission sets" from the left navigation pane.
- Choose "Create a permission set."
- Create a Custom Permission Set.
- Choose "Create a custom permission set."
- Give your permission set a name and description.
- Click "Next: Permissions."
- Attach S3 Policies.
- Click "Create inline policy."
- Use a JSON policy to grant S3 access (
src/main/resources/s3-bucket-access-policy.json
). - Click "Create Policy" and then "Next: Tags" (optional), then "Next: Review."
- Review the permission set and click "Create."
- Assign the Permission Set to a User.
- Go back to the IAM Identity Center dashboard.
- Navigate to "AWS accounts."
- Select the account you want to assign the permission set to.
- Click "Assign users."
- Choose the user you want to assign the permission set to.
- Select the permission set you created (
S3AccessPermissionSet
). - Click "Assign."
-
Ensure you have configured your AWS CLI to use SSO:
aws configure sso
-
Authenticate using AWS SSO:
aws sso login --profile <profile-name>
-
Verify access:
Try uploading a file to your S3 bucket:
aws s3 cp <file> s3://<bucket-name> --profile <profile-name>