[英]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.