我試圖將一些信息保存到我的DynamoDB表中。該表已創建,但我收到以下錯誤。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();
}
}
所有幫助表示讚賞。
以下線程似乎可以解決問題。當我稍後有機會時,我會爲此寫下正式答案:https://forums.aws.amazon.com/thread.jspa?messageID=463216 – chaotic3quilibrium