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
• 3,040 points
615 views

1 answer to this question.

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,560 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,520 points

edited Jul 13, 2018 by Priyaj 237 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,520 points
544 views
+13 votes
2 answers

Git management technique when there are multiple customers and need multiple customization?

Consider this - In 'extended' Git-Flow, (Git-Multi-Flow, ...READ MORE

answered Mar 26, 2018 in DevOps & Agile by DragonLord999
• 8,380 points
121 views
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,560 points
113 views