Mobile App registration and upload the profile images to AWS S3 bucket

Stephie John
3 min readMay 24, 2022

Lia infraservices-being an AWS partner company, we always use AWS cloud migration services to ensure get the durable application for our customers. In this blog, we are going to look into Mobile App registration and Upload the Profile Images to the AWS S3 bucket by the expert Mobile App Development company in Chennai.

We have decided to use AWS S3 and the AWS Cognito service for any user to store their profile picture while registering into the mobile application.

Check out: How to solve “Access denied in AWS S3 Bucket“?

How to upload the profile image to AWS S3 Bucket?

  1. Created an S3 bucket in Bahrain region as our customer was from Middle east, and so to reduce the latency, we wanted to have all the services in that region.
  2. Set up the permissions necessary like bucket policy and CORS.

Bucket policy

{

“Version”: “2012–10–17”,

“Id”: “Policy1626866950426”,

“Statement”: [

{

“Sid”: “Stmt1626866945113”,

“Effect”: “Allow”,

“Principal”: “*”,

“Action”: “s3:*”,

“Resource”: “arn:aws:s3:::bucket_name/*”

}

]

}

CORS

[

{

“AllowedHeaders”: [

“*”

],

“AllowedMethods”: [

“PUT”,

“POST”,

“DELETE”

],

“AllowedOrigins”: [

“*”

],

“ExposeHeaders”: []

},

{

“AllowedHeaders”: [],

“AllowedMethods”: [

“GET”

],

“AllowedOrigins”: [

“*”

],

“ExposeHeaders”: []

}

]

Once the bucket was created, we had to enable AWS Cognito to allow the user to authenticate to access AWS resources.

From the Cognito console, selected “Manage Identity Pool”

Gave a name to the identity pool

Under “Unauthenticated identities“ Enabled access to unauthenticated identities created the Pool.

Learn About: How to enable cross-account I am accessing using AWS console.

That automatically created two IAM roles

  1. Unauthenticated role
  2. Authenticated role

Note: To make the permission even granular, we can add the S3 bucket the Cognito to have permission to. But, in our case, we did not need to do any changes to the existing inline policy.

Once all are set correctly, provide the information to the developer as

BUCKET_NAME=”Bucket_name”

ENDPOINT=”https://s3.me-south-1.amazonaws.com"

BASE_S3_URL=”https://s3.me-south-1.amazonaws.com/bucket_name/"

POOL_ID=”me-south-1:ec9f9bfe-5c19–419a-91bc-f757957d080e”

The Android developers updated that into their code,

Once they uploaded the code and tried to test, they were getting the error as below.

Error Message:

IdentityPool ‘me-south-1:ec9f9bfe-5c19–419a-91bc-f757957d080e’ not found. (Service: AmazonCognitoIdentity; Status Code: 400; Error Code: ResourceNotFoundException; Request ID: a9cb68–9e9a-4693-aa34–9ca45e)

After some research, it was found that the S3 service in the Bahrain region does not accept any data transfer, it needs some other component to get that done.

To reduce the overhead, we decided to move the S3 bucket and Cognito to other supported AWS regions and then the code was working fine.

The application was able to upload the user profile during the registration.

Conclusion:

When you upload a file to Amazon S3, it is stored as an S3 object. You can have an unlimited number of objects in a bucket. Before you can upload files to an Amazon S3 bucket, you need to write permissions for the bucket. For more information about how to do mobile app registration and upload the profile images to the AWS S3 bucket, please contact Lia Infraservices — The Professional AWS Cloud Migration Services Provider.

You may also like to read this: How to transfer files between AWS S3 and AWS ec2.

We at Lia Infraserces the Top SEO Services/Company in Chennai are expertise in website designing, build modern, multi gadget-friendly, multi-platform support Android & iOS App Development Company in Chennai. We can help your targeted audience locate your product or service based on customer interest through our top web app development company in Chennai

--

--