[英]DynamoDB - The security token included in the request is expired
我正在尝试将一些信息保存到我的DynamoDB表中。 该表已经创建,但是我收到以下错误。
Caused by: com.amazonaws.AmazonServiceException: The security token included in the
request is expired (Service: AmazonDynamoDBv2; Status Code: 400; Error Code:
ExpiredTokenException; Request ID: MA87ST04UPA57CMUJQIS8DBS4FVV4KQNSO5AEMVJF66Q9ASUAAJG)
值得注意的是,我设法将信息保存一次,但是在第一次之后不再保存。
这是我的代码。
public class SignUp extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.test);
if (android.os.Build.VERSION.SDK_INT > 9) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
}
}
public void signUp(View view){
CognitoCachingCredentialsProvider cognitoProvider = new CognitoCachingCredentialsProvider(
this, // get the context for the current activity
"us-east-1:xxxxx", /* Identity Pool ID */
Regions.US_EAST_1 /* Region */
);
AmazonDynamoDBClient ddbClient = new AmazonDynamoDBClient(cognitoProvider);
DynamoDBMapper mapper = new DynamoDBMapper(ddbClient);
TextView name = (TextView)findViewById(R.id.Name);
TextView email = (TextView)findViewById(R.id.email);
TextView username = (TextView)findViewById(R.id.username);
TextView password = (TextView)findViewById(R.id.password);
TextView phone = (TextView)findViewById(R.id.phone);
UserInfo userInfo = new UserInfo();
userInfo.setName(name.getText().toString());
userInfo.setEmail(email.getText().toString());
userInfo.setUsername(username.getText().toString());
userInfo.setPassword(password.getText().toString());
userInfo.setPhone(phone.getText().toString());
mapper.save(userInfo);
Toast.makeText(this, "Finished!", Toast.LENGTH_LONG).show();
}
}
感谢所有帮助。
此错误与2月Cognito公告无关。 在我看来,这似乎是时钟偏斜错误。 如果您将仿真器打开了一段时间或更改了手机上的时钟,则从SDK生成的令牌可能与AWS期望的不匹配。SDK可能会自动更正时钟偏斜错误。 您可以检查设备/仿真器上的时钟并查看是否存在问题吗? 如果可以的话,我会对有助于改进SDK的确切情况感兴趣。
谢谢,韦斯顿
如果它以前可以工作,现在不起作用,则可能与该AWS官方公告有关 :
如果您在2015年2月之前创建了身份池,则需要将角色与身份池重新关联才能使用此构造函数。 为此,请打开cognito控制台,选择您的身份池,单击“编辑身份池”,指定经过身份验证和未经身份验证的角色,然后保存更改。
所说的构造函数是这样的:
CognitoCachingCredentialsProvider cognitoProvider = new CognitoCachingCredentialsProvider(
myActivity.getContext(), // get the context for the current activity
"COGNITO_IDENTITY_POOL", /* Identity Pool ID */
Regions.US_EAST_1 /* Region */);
没关系...在跳来跳去时,我误读了上面的Java代码,该代码实际上正确地传递了AWSCredentialsProvider
(而不是AWSCredentials
)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.