📔
ServerlessDocs - Serverless File Service
  • Introduction
  • Why Serverless!!
  • Prerequisites
  • User Management
    • Authentication
    • Amazon Cognito
    • Create the User Pool
    • Create an App Client
    • Integrate the app with Cognito User Pool
    • Create the Identity Pool
    • Validate the setup
    • Troubleshooting
  • Manage Documents with AWS S3
    • Authorization
    • Update Cognito Identity Pool Auth Role
    • S3 Documents Bucket Folder Structure
    • Validate the Access Permissions
    • Public and Private files access
    • Upload Files to S3
    • Download Files
    • Delete Files
    • Share Files
  • More Security Configurations
    • Cognito user emails
    • Password policies
    • Allow only Organization and Whitelisted users to Signup
    • Allow admin users to upload Public files
    • Notify Admin users when a new user signup
    • Enable Multi-factor Authentication (MFA)
  • User Operations
    • Password Reset / Forgot Password
    • Resend Verification Code
  • Serverless APIs
    • APIs
    • Secure APIs using API Gateway Authorizer
    • Access Cognito values in Lambda function
    • Authorize APIs with OAuth 2 Scope
    • Fine-grained Access with AssumeRole
    • Notify Admin users on large file uploads
    • Generate a Month-To-Date Usage report
  • Source Code and Setup
    • Source Code
    • IAM Policies
    • S3 Bucket Policies
    • Suggestions / Feedback
    • More References
  • Deployment
    • AWS SAM
    • Serverless Framework
  • Contributors
    • Team
Powered by GitBook
On this page

Was this helpful?

  1. Manage Documents with AWS S3

Update Cognito Identity Pool Auth Role

PreviousAuthorizationNextS3 Documents Bucket Folder Structure

Last updated 4 years ago

Was this helpful?

Our application allows users to upload, share, and view files. We will be using the AWS S3 to store and view files. To make sure our users can access their folders properly, we will have to first configure the S3 access permissions to logged-in users.

  • Go to the Identity Pool and select Edit identity pool from top right

  • Copy the Authenticated role and go to the IAM console

  • Search for the IAM role and select Attach policies

  • Select Create Policy option

  • Copy the below policy JSON and create the policy

Unauthenticated and Authenticated roles are very intuitive features. As an application developer, I would just need to assign proper permissions to these roles to make sure that my application users get correct access based on their status.

It is possible to configure a rule-based role assignment as well via Identity Pool. For example, you can create a rule that assigns a specific IAM role for users with a custom:dept custom attribute value of Sales. cust: prefix is required for custom attributes.

Now, create a new IAM policy that we can assign to the authenticated role that will allow our users to access the /public-files folder.

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "AllowListingOfPublicFolder",
            "Effect": "Allow",
            "Action": "s3:ListBucket",
            "Resource": "arn:aws:s3:::<S3 files bucket>",
            "Condition": {
                "StringLike": {
                    "s3:prefix": [
                        "public-files/*"
                    ]
                }
            }
        }
    ]
}

The above policy will grant read access to the public folder.

Make sure your files bucket has the correct CORS configuration. You can refer to the Introduction section to get the configurations.

Assign the above policy to the role and test the web application again.

Identity pool Authenticated and Unauthenticated roles