aws/DynamoProvider.js
/**
		 * Creates a new table, if it does not already exist, and returns the table's
		 * metadata once the table becomes ready.
		 *
		 * @public
		 * @param {Table} definition - Describes the schema of the table to create.
		 * @returns {Promise<Table>}
		 */
Creates a new table, if it does not already exist, and returns the table's
metadata once the table becomes ready.

@public
@param {Table} definition - Describes the schema of the table to create.
@returns {Promise}
Creates a new table if it does not already exist and returns the table ' s metadata once the table becomes ready . @public @param { Table } definition - Describes the schema of the table to create . @returns { Promise }
createTable(definition) {
			return Promise.resolve()
				.then(() => {
					assert.argumentIsRequired(definition, 'definition', Table, 'Table');
					checkReady.call(this);
					const qualifiedTableName = definition.name;
					const getTableForCreate = () => {
						return getTable.call(this, qualifiedTableName)
							.then((tableData) => {
								if (tableData.TableStatus === 'ACTIVE') {
									return getTimeToLiveSettings.call(this, qualifiedTableName)
										.then((ttlData) => {
											logger.info('Table ready [', qualifiedTableName, ']');
											return Promise.resolve(Object.assign({ }, tableData, ttlData));
										}).catch((error) => {
											let promise;
											if (is.string(error) && error.includes('AccessDeniedException') && error.includes('dynamodb:DescribeTimeToLive')) {
												logger.error(error);
												promise = Promise.resolve(tableData);
											} else {
												promise = Promise.reject(error);
											}
											return promise;
										});
								} else {
									logger.debug('Table not yet ready [', qualifiedTableName, ']');
									return Promise.reject();
								}
							});
					};
					return promise.build((resolveCallback, rejectCallback) => {
						logger.info('Creating table [', qualifiedTableName, ']');
						this._dynamo.createTable(definition.toTableSchema(), (error, data) => {
							if (error) {
								if (is.string(error.message) && error.message === `Table already exists: ${qualifiedTableName}`) {
									logger.info('Unable to create table [', qualifiedTableName, '], table already exists');
									return getTableForCreate.call(this, qualifiedTableName)
										.then((tableData) => {
											const serverDefinition = TableBuilder.fromDefinition(tableData);
											if (definition.equals(serverDefinition, true)) {
												resolveCallback(serverDefinition);
											} else {
												rejectCallback(new Error(`The server definition of the table [ ${qualifiedTableName} ] does not match the expected definition.`));
											}
										}).catch((e) => {
											rejectCallback(e);
										});
								} else {
									logger.error(error);
									rejectCallback('Failed to create DynamoDB tables', error);
								}
							} else {
								logger.info('Created table [', qualifiedTableName, '], waiting for table to become ready');
								return this._scheduler.backoff(() => getTableForCreate.call(this, qualifiedTableName), 2000)
									.then((tableData) => {
										let ttlPromise;
										if (definition.ttlAttribute) {
											logger.info(`Updating time-to-live configuration for table [ ${definition.name} ]`);
											ttlPromise = this._dynamo.updateTimeToLive(definition.toTtlSchema()).promise()
												.then((ttlData) => {
													logger.info(`Updated time-to-live configuration for table [ ${definition.name} ]`);
													return ttlData;
												});
										} else {
											ttlPromise = Promise.resolve(null);
										}
										return ttlPromise.then((ttlData) => {
											const adjusted = Object.assign({ }, tableData, ttlData || { });
											resolveCallback(TableBuilder.fromDefinition(adjusted));
										});
									}).catch((e) => {
										rejectCallback(e);
									});
							}
						});
					});
				});
		}
createTable ( definition ) { return Promise . resolve ( ) . then ( ( ) => { assert . argumentIsRequired ( definition , 'definition' , Table , 'Table' ) ; checkReady . call ( this ) ; const qualifiedTableName = definition . name ; const getTableForCreate = ( ) => { return getTable . call ( this , qualifiedTableName ) . then ( ( tableData ) => { if ( tableData . TableStatus === 'ACTIVE' ) { return getTimeToLiveSettings . call ( this , qualifiedTableName ) . then ( ( ttlData ) => { logger . info ( 'Table ready [' , qualifiedTableName , ']' ) ; return Promise . resolve ( Object . assign ( { } , tableData , ttlData ) ) ; } ) . catch ( ( error ) => { let promise ; if ( is . string ( error ) && error . includes ( 'AccessDeniedException' ) && error . includes ( 'dynamodb:DescribeTimeToLive' ) ) { logger . error ( error ) ; promise = Promise . resolve ( tableData ) ; } else { promise = Promise . reject ( error ) ; } return promise ; } ) ; } else { logger . debug ( 'Table not yet ready [' , qualifiedTableName , ']' ) ; return Promise . reject ( ) ; } } ) ; } ; return promise . build ( ( resolveCallback , rejectCallback ) => { logger . info ( 'Creating table [' , qualifiedTableName , ']' ) ; this . _dynamo . createTable ( definition . toTableSchema ( ) , ( error , data ) => { if ( error ) { if ( is . string ( error . message ) && error . message === ` ${ qualifiedTableName } ` ) { logger . info ( 'Unable to create table [' , qualifiedTableName , '], table already exists' ) ; return getTableForCreate . call ( this , qualifiedTableName ) . then ( ( tableData ) => { const serverDefinition = TableBuilder . fromDefinition ( tableData ) ; if ( definition . equals ( serverDefinition , true ) ) { resolveCallback ( serverDefinition ) ; } else { rejectCallback ( new Error ( ` ${ qualifiedTableName } ` ) ) ; } } ) . catch ( ( e ) => { rejectCallback ( e ) ; } ) ; } else { logger . error ( error ) ; rejectCallback ( 'Failed to create DynamoDB tables' , error ) ; } } else { logger . info ( 'Created table [' , qualifiedTableName , '], waiting for table to become ready' ) ; return this . _scheduler . backoff ( ( ) => getTableForCreate . call ( this , qualifiedTableName ) , 2000 ) . then ( ( tableData ) => { let ttlPromise ; if ( definition . ttlAttribute ) { logger . info ( ` ${ definition . name } ` ) ; ttlPromise = this . _dynamo . updateTimeToLive ( definition . toTtlSchema ( ) ) . promise ( ) . then ( ( ttlData ) => { logger . info ( ` ${ definition . name } ` ) ; return ttlData ; } ) ; } else { ttlPromise = Promise . resolve ( null ) ; } return ttlPromise . then ( ( ttlData ) => { const adjusted = Object . assign ( { } , tableData , ttlData || { } ) ; resolveCallback ( TableBuilder . fromDefinition ( adjusted ) ) ; } ) ; } ) . catch ( ( e ) => { rejectCallback ( e ) ; } ) ; } } ) ; } ) ; } ) ; }
Creates a new table, if it does not already exist, and returns the table's
 metadata once the table becomes ready.
Creates a new table if it does not already exist and returns the table ' s metadata once the table becomes ready .