This sample demonstrates how to use the high-level class TransferUtility to perform download and upload tasks and manage the tasks. You can also follow the tutorial for a step-by-step guide in understanding the S3TransferUtilitySample.
-
Create a identity pool
- Go to Amazon Cognito Console and choose
Manage Identity Pools. - Click
Create new Identity poolbutton on the top left of the console. - Give a name for the Identity pool and check
Enable access to unauthenticated identitiesunder theUnauthenticated Identitiessection, clickCreate poolbutton on the bottom right. - To enable Cognito Identities to access your resources, expand the
View Detailssection to see the two roles that are to be created. Make a note of theunauthrole whose name is of the formCognito_<IdentityPoolName>Unauth_Role. Now clickAllowbutton in the bottom right of the console. - Under
Get AWSCredentialssection, in the code snippet to createCognitoCachingCredentialsProvider, find the Identity pool ID and the AWS region and make note of them. You will need to add to the sample application later.
- Go to Amazon Cognito Console and choose
-
Set up permissions
- Go to Amazon IAM Console and select "Roles".
- Select the
unauthrole you just created in step 1, which is of the formCognito_<IdentityPoolName>Unauth_Role. - Select
Attach Policy, then findAmazonS3FullAccessand attach it it to the role. - Note: This will grant users in the identity pool full access to all buckets and operations in S3. In a real app, you should restrict users to only have access to the resources they need.
-
Create a bucket
- Go to Amazon S3 Console and click
Create bucket. - Enter a name for the bucket that is DNS-compliant. For restrictions on bucket naming refer Bucket Restrictions and Limitations.
- Choose the region that you want the bucket to be created.
- Click
Create. Note the name and the region of the bucket that was created.
- Go to Amazon S3 Console and click
-
Import the sample project
- Import the sample as Android project into your IDE of choice.
- Open
awsconfiguration.jsonin /res/raw directory. - Update
PoolIdwith the ID of the Cognito Identity Pool created in Step-1. - Update
Regionwith the region of the Cognito Identity Pool created from Step-1. For example,us-east-1. TheRegioncolumn in Amazon Cognito Identity Regions represents the region string."CredentialsProvider": { "CognitoIdentity": { "Default": { "PoolId": "REPLACE_ME", "Region": "REPLACE_ME" } } }, - Update
Bucketwith the name of the S3 Bucket created in Step-3. - Update
Regionwith the region of the S3 Bucket created from Step-3. For example,us-east-1. TheRegioncolumn in Amazon S3 Regions represents the region string."S3TransferUtility": { "Default": { "Bucket": "REPLACE_ME", "Region": "REPLACE_ME" } }
-
Import the AWS SDK for Android
- This application used
Gradleto resolve the dependencies required by the app and fetches from maven. This app depends onaws-android-sdk-s3inbuild.gradle.
- This application used
-
Build and Run the sample