What is the best way to check if table exists in DynamoDB?

0 votes

What is the best way to check if table exists in DynamoDb?

I would appreciate it if the code would be in PHP.

Nov 30, 2018 in AWS by datageek
• 2,940 points
481 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes

This function gives you a nice boolean to use in scripts.

use Aws\DynamoDb\Exception\ResourceNotFoundException; // <-- make sure this line is at the top

    public function TableExists($tableName) {

    $ddb = DynamoDbClient::factory(array('region' => 'us-east-1')); // EC2 role security

    try {
        $result = $ddb->describeTable(array(
            "TableName" => $tableName
        ));
    } catch (ResourceNotFoundException $e) {
        // if this exception is thrown, the table doesn't exist
        return false;
    }

    // no exception thrown? table exists!
    return true;
}

Hopefully this complete working code helps some of you.

answered Nov 30, 2018 by Archana
• 5,360 points

Related Questions In AWS

0 votes
1 answer

What happens to data if the data center goes down in AWS?

When it comes to the security and ...READ MORE

answered Jul 13, 2018 in AWS by Priyaj
• 56,140 points

edited Jul 13, 2018 by Priyaj 166 views
0 votes
1 answer

I'm trying to integrate Bitbucket into AWS Code Pipeline? What is the best approach?

You can integrate Bitbucket with AWS CodePipeline ...READ MORE

answered Aug 17, 2018 in AWS by Priyaj
• 56,140 points
395 views
+13 votes
2 answers
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

What is the maximum storage capacity of a node in Redshift?

You can create a cluster using either ...READ MORE

answered Oct 26, 2018 in AWS by Archana
• 5,360 points
88 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.