Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function waitForAsyncOperationStatus({
TableName,
id,
status,
retries = 10
}) {
const { Item } = await dynamodb().getItem({
TableName,
Key: { id: { S: id } }
}).promise();
if (Item.status.S === status || retries <= 0) return Item;
await sleep(2000);
return waitForAsyncOperationStatus({
TableName,
id,
status,
retries: retries - 1
});
}
params.AttributeDefinitions.push({
AttributeName: range.name,
AttributeType: range.type
});
}
if (attributes) {
attributes.forEach((attribute) => {
params.AttributeDefinitions.push({
AttributeName: attribute.name,
AttributeType: attribute.type
});
});
}
const output = await aws.dynamodb().createTable(params).promise();
await aws.dynamodb().waitFor('tableExists', { TableName: tableName }).promise();
if (!inTestMode()) await enableStream(tableName);
return output;
}
};
if (range) {
params.KeySchema.push({
AttributeName: range.name,
KeyType: 'RANGE'
});
params.AttributeDefinitions.push({
AttributeName: range.name,
AttributeType: range.type
});
}
const output = await aws.dynamodb().createTable(params).promise();
await aws.dynamodb().waitFor('tableExists', { TableName: tableName }).promise();
if (!inTestMode()) await enableStream(tableName);
return output;
}
const recordsCount = flatten([executionRecord, granuleRecords, pdrRecord]).length;
if (recordsCount > 10 || inTestMode()) {
if (executionRecord) await executionModel.create(executionRecord);
if (pdrRecord) await pdrModel.create(pdrRecord);
await granuleModel.create(granuleRecords);
}
else if (recordsCount > 0) {
const TransactItems = flatten([
buildTransactPut(executionModel.tableName, executionRecord),
buildTransactPut(pdrModel.tableName, pdrRecord),
granuleRecords.map(buildTransactPut(granuleModel.tableName))
]).filter(isNotNil);
await dynamodb().transactWriteItems({ TransactItems }).promise();
}
return {
sf: executionRecord,
pdr: pdrRecord,
granule: isEmpty(granuleRecords) ? null : granuleRecords
};
}
async () =>
aws.dynamodb().describeTable({ TableName: tableName }).promise()
.then((response) => response.TableStatus !== 'UPDATING'),
{ interval: 5 * 1000 }
async function enableStream(tableName) {
const params = {
TableName: tableName,
StreamSpecification: {
StreamEnabled: true,
StreamViewType: 'NEW_AND_OLD_IMAGES'
}
};
await aws.dynamodb().updateTable(params).promise();
await pWaitFor(
async () =>
aws.dynamodb().describeTable({ TableName: tableName }).promise()
.then((response) => response.TableStatus !== 'UPDATING'),
{ interval: 5 * 1000 }
);
}
async function deleteTable(tableName) {
const output = await aws.dynamodb().deleteTable({
TableName: tableName
}).promise();
await aws.dynamodb().waitFor('tableNotExists', { TableName: tableName }).promise();
return output;
}
AttributeName: range.name,
AttributeType: range.type
});
}
if (attributes) {
attributes.forEach((attribute) => {
params.AttributeDefinitions.push({
AttributeName: attribute.name,
AttributeType: attribute.type
});
});
}
const output = await aws.dynamodb().createTable(params).promise();
await aws.dynamodb().waitFor('tableExists', { TableName: tableName }).promise();
if (!inTestMode()) await enableStream(tableName);
return output;
}
}
};
if (range) {
params.KeySchema.push({
AttributeName: range.name,
KeyType: 'RANGE'
});
params.AttributeDefinitions.push({
AttributeName: range.name,
AttributeType: range.type
});
}
const output = await aws.dynamodb().createTable(params).promise();
await aws.dynamodb().waitFor('tableExists', { TableName: tableName }).promise();
if (!inTestMode()) await enableStream(tableName);
return output;
}