HTG
HTG

Reputation: 584

DynamoDB - The security token included in the request is expired

I am attempting to save a bit of info to my DynamoDB Table. The table has been created already, but I received the following error.

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)

It's worth noting that I managed to get the info to save once, but it no longer saves after that first time.

Here's my code.

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();

    }
}

All help is appreciated.

Upvotes: 2

Views: 4325

Answers (3)

chaotic3quilibrium
chaotic3quilibrium

Reputation: 5924

Nevermind...in jumping around, I misread the above Java code which is in fact correctly passing an AWSCredentialsProvider (as opposed to just AWSCredentials).

Upvotes: 0

WestonE
WestonE

Reputation: 702

This error is unrelated to the February Cognito announcement. This looks to me like a clock skew error. If you have left an emulator open for awhile or changed the clock on a phone it is possible the token generated from the SDK does not match what AWS is expecting... The SDK is suppose to automatically correct clock skew errors. Can you check the clock on device/emulator and see if this is the problem? If it is I'd be interested in the exact circumstances to help improve the SDK.

Thanks, Weston

Upvotes: 4

inmyth
inmyth

Reputation: 9050

If it worked before and it doesn't now maybe it has something to do with this AWS official announcement:

If you created your identity pool before February 2015, you will need to reassociate your roles with your identity pool in order to use this constructor. To do so, open the cognito console, select your identity pool, click Edit Identity Pool, specify your authenticated and unauthenticated roles, and save the changes.

And the said constructor is this:

CognitoCachingCredentialsProvider cognitoProvider = new  CognitoCachingCredentialsProvider(
    myActivity.getContext(),    // get the context for the current activity
    "COGNITO_IDENTITY_POOL",    /* Identity Pool ID */
    Regions.US_EAST_1           /* Region */);

Upvotes: 1

Related Questions