My Goal:
Upload photos from iOS to a common AWS S3 bucket with the simplest code possible
What I've Tried:
Assumptions of Best Practices:
I assume that Cognito is the default way to set up image uploading after all of the reading I've done. However, I have two problems with doing it this way:
My Questions:
Cognito Identity is a free service so you don't really have to pay for it. Also you really shouldn't be using hardcoded credentials in your app since it can be easily decompiled and retrieved which is not the scenario in case of a server side code.
For iOS SDK you can use AWSStaticCredentialsProvider
as a way to provide the static credentials to any service client.
AWSStaticCredentialsProvider *credentialsProvider = [AWSStaticCredentialsProvider credentialsWithAccessKey:@"YourAccessKey" secretKey:@"YourSecretKey"];
Again you really shouldn't be doing this in a production app.
I suggest that never use AWS in Moblie Application without Cognito.
If you still want to do that you can create an IAM user set policy to your bucket resources and put the IAM user credential to your code
AWSCredentials credentials = new AWSCredentials() {
@Override
public String getAWSSecretKey() {
// TODO Auto-generated method stub
return "YOUR_SECRETKEY";
}
@Override
public String getAWSAccessKeyId() {
// TODO Auto-generated method stub
return "YOUR_IAM_AWS_ACCESS_KEY_ID";
}
};
AmazonS3 s3 = new AmazonS3Client(credentials);
Note that the method is dangerous to use!! You can set AWS S3 Bucket permission policy instead: S3 permission policy.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With