使用认知和API网关访问REST的问题
在我的一生中,我找不到一个简单的例子,说明如何在AWS服务器上调用安全的REST。
我打电话
CognitoCachingCredentialsProvider credentialsProvider = new CognitoCachingCredentialsProvider(
ProfileViewActivity.this, // get the context for the current activity
AMAZON_COGNITO_IDENTITY_POOL_ID, // your identity pool id
Regions.US_EAST_1 //Region
);然后尝试调用我们的服务器,这是该池的一部分。我不停地收回“禁止”。
我应该如何处理credentialsProvider在HttpURLConnection头中的操作?
更新:
好的,在AWS生成的SDK中正确地使用APIGateWay,但是不确定如何更改生成的文件:
private class MyAsyncTask extends AsyncTask<String, Void, String> {
private TextView textView;
public MyAsyncTask() {
}
@Override
protected String doInBackground(String... strings) {
AWSCredentialsProvider credenetialsProvider = new CognitoCachingCredentialsProvider(
ProfileViewActivity.this, // activity context
AMAZON_COGNITO_IDENTITY_POOL_ID, // Cognito identity pool id
Regions.US_EAST_1 // region of Cognito identity pool
);
ApiClientFactory factory = new ApiClientFactory()
.credentialsProvider(credenetialsProvider)
.region("us-east-1")
.endpoint("https://myendpoint")
.apiKey("xxxxxxxxxxxxxxxxxxxxxxx");
// MyClient is the AWS Android SDK Generated class
final MyClient client = factory.build(MyClient.class);
client.feedGet();
String str = client.testGet().toString();
Log.d("###", "here after test" +client.testGet().toString());
return "DONE";
}
@Override
protected void onPostExecute(String temp) {
Log.d("####", "onPostExecute");
}
}然后
private class MyAsyncTask extends AsyncTask<String, Void, String> {
private TextView textView;
public MyAsyncTask() {
}
@Override
protected String doInBackground(String... strings) {
AWSCredentialsProvider credenetialsProvider = new CognitoCachingCredentialsProvider(
ProfileViewActivity.this, // activity context
AMAZON_COGNITO_IDENTITY_POOL_ID, // Cognito identity pool id
Regions.US_EAST_1 // region of Cognito identity pool
);
ApiClientFactory factory = new ApiClientFactory()
.credentialsProvider(credenetialsProvider)
.region("us-east-1")
.endpoint("https://myendpoint")
.apiKey("xxxxxxxxxxxxxxxxxxxxxxx");
// MyClient is the AWS Android SDK Generated class
final MyClient client = factory.build(MyClient.class);
client.feedGet();
String str = client.testGet().toString();
Log.d("###", "here after test" +client.testGet().toString());
return "DONE";
}
@Override
protected void onPostExecute(String temp) {
Log.d("####", "onPostExecute");
}
}========= MyClient.java - Android生成的文件
@com.amazonaws.mobileconnectors.apigateway.annotation.Service(endpoint = https:myaws_server)
public interface MyClient {
@com.amazonaws.mobileconnectors.apigateway.annotation.Operation(path = \"/test\", method = "GET")
Empty testGet();发布于 2016-06-03 03:10:37
如果您使用的是AWS网关,您可以独立使用它,而无需使用AWS认知。是一个http服务,就像您服务器的代理或AWS函数的网关一样。
aws api网关
https://stackoverflow.com/questions/37597549
复制相似问题