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 pool
button on the top left of the console. - Give a name for the Identity pool and check
Enable access to unauthenticated identities
under theUnauthenticated Identities
section, clickCreate pool
button on the bottom right. - To enable Cognito Identities to access your resources, expand the
View Details
section to see the two roles that are to be created. Make a note of theunauth
role whose name is of the formCognito_<IdentityPoolName>Unauth_Role
. Now clickAllow
button in the bottom right of the console. - Under
Get AWSCredentials
section, 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
unauth
role you just created in step 1, which is of the formCognito_<IdentityPoolName>Unauth_Role
. - Select
Attach Policy
, then findAmazonS3FullAccess
and 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.json
in /res/raw directory. - Update
PoolId
with the ID of the Cognito Identity Pool created in Step-1. - Update
Region
with the region of the Cognito Identity Pool created from Step-1. For example,us-east-1
. TheRegion
column in Amazon Cognito Identity Regions represents the region string."CredentialsProvider": { "CognitoIdentity": { "Default": { "PoolId": "REPLACE_ME", "Region": "REPLACE_ME" } } },
- Update
Bucket
with the name of the S3 Bucket created in Step-3. - Update
Region
with the region of the S3 Bucket created from Step-3. For example,us-east-1
. TheRegion
column 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
Gradle
to resolve the dependencies required by the app and fetches from maven. This app depends onaws-android-sdk-s3
inbuild.gradle
.
- This application used
-
Build and Run the sample