I want to have different configuration for debug
and release
builds. All the configuration is stored inside awsconfiguration.json
, for example I have two different config files how can I set which file should be used.
When using AWSMobileClient.getInstance()
it gets default configuration from file awsconfiguration.json
Configuration file example:
{
"Version": "1.0",
"CredentialsProvider": {
"CognitoIdentity": {
"Default": {
"PoolId": "DIFFERENT_VALUES",
"Region": "DIFFERENT_VALUES"
}
}
},
"IdentityManager": {
"Default": {}
},
"CognitoUserPool": {
"Default": {
"AppClientSecret": "DIFFERENT_VALUES",
"AppClientId": "DIFFERENT_VALUES",
"PoolId": "DIFFERENT_VALUES",
"Region": "DIFFERENT_VALUES"
}
}
}
Update
There is option to use different awsconfiguration.json
by puting different files in main\res\raw
and release\res\raw
, for example by following this answer and it works.
But I'm wondering whether there is an option to do it programmatically.
This can also be acheived by setting the configuration value in AWSConfiguration and then initializing the AWSMobileClient.
AWSConfiguration awsConfiguration = new AWSConfiguration(context);
awsConfiguration.setConfiguration("Stage"); // BuildConfig can be used here.
AWSMobileClient.getInstance().initialize(context, awsConfiguration, new Callback<UserStateDetails>() {
@Override
public void onResult(UserStateDetails userStateDetails) {
}
@Override
public void onError(Exception e) {
}
});
And the awsconfiguration.json file can be updated as below
{
"Version": "1.0",
"CredentialsProvider": {
"CognitoIdentity": {
"Default": {
"PoolId": "DIFFERENT_VALUES",
"Region": "DIFFERENT_VALUES"
},
"Stage": {
"PoolId": "STAGE_VALUES",
"Region": "STAGE_VALUES"
}
}
},
"IdentityManager": {
"Default": {},
"Stage": {}
},
"CognitoUserPool": {
"Default": {
"AppClientSecret": "DIFFERENT_VALUES",
"AppClientId": "DIFFERENT_VALUES",
"PoolId": "DIFFERENT_VALUES",
"Region": "DIFFERENT_VALUES"
},
"Stage": {
"AppClientSecret": "STAGE_VALUES",
"AppClientId": "STAGE_VALUES",
"PoolId": "STAGE_VALUES",
"Region": "STAGE_VALUES"
}
}
}
I've been trying to achieve something similar; selecting an AWS configuration at runtime based on a selected profile. I got it partially working by hacking the AWS SDK but then stumbled across release notes for AWS SDK version 2.11.0. Quoting:
Added the option of passing the configuration as an in-memory object (i.e.
[String: Any]/NSDictionary
) instead of the defaultawsconfiguration.json
through the new API
I've also found it documented(!) in the amplify getting started guide here.
So since 9th September 2019 it IS possible to select an AWS configuration at runtime.
Edit: Just noticed that this question is for Android rather than iOS. I'm not an Android developer but a quick searched revealed something similar in AWS Android SDK release 2.13.6 (7th June 2019). Quoting the release notes:
Add
AWSConfiguration(JSONObject)
constructor to construct aAWSConfiguration
object from the configuration passed via a JSONObject
... which looks promising.
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