Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// This is an LSI.
// Add the new secondary index and update the table's attribute definitions.
tableResource.Properties.LocalSecondaryIndexes = append(
tableResource.Properties.LocalSecondaryIndexes,
new LocalSecondaryIndex(baseIndexProperties)
)
} else {
// This is a GSI.
// Add the new secondary index and update the table's attribute definitions.
tableResource.Properties.GlobalSecondaryIndexes = append(
tableResource.Properties.GlobalSecondaryIndexes,
new GlobalSecondaryIndex({
...baseIndexProperties,
ProvisionedThroughput: Fn.If(
ResourceConstants.CONDITIONS.ShouldUsePayPerRequestBilling,
Refs.NoValue,
{
ReadCapacityUnits: Fn.Ref(ResourceConstants.PARAMETERS.DynamoDBModelTableReadIOPS),
WriteCapacityUnits: Fn.Ref(ResourceConstants.PARAMETERS.DynamoDBModelTableWriteIOPS)
}
) as any,
})
)
}
const existingAttrDefSet = new Set(tableResource.Properties.AttributeDefinitions.map(ad => ad.AttributeName));
for (const attr of attrDefs) {
if (!existingAttrDefSet.has(attr.AttributeName)) {
tableResource.Properties.AttributeDefinitions.push(attr);
}
}
}
}
// If the GSI does not exist yet then add it.
const existingGSI = gsis.find(gsi => gsi.IndexName === connectionGSIName)
if (!existingGSI) {
const keySchema = [new KeySchema({ AttributeName: connectionAttributeName, KeyType: 'HASH' })]
if (sortField) {
keySchema.push(new KeySchema({ AttributeName: sortField.name, KeyType: 'RANGE' }))
}
gsis.push(new GlobalSecondaryIndex({
IndexName: connectionGSIName,
KeySchema: keySchema,
Projection: new Projection({
ProjectionType: 'ALL'
}),
ProvisionedThroughput: Fn.If(
ResourceConstants.CONDITIONS.ShouldUsePayPerRequestBilling,
Refs.NoValue,
{
ReadCapacityUnits: Fn.Ref(ResourceConstants.PARAMETERS.DynamoDBModelTableReadIOPS),
WriteCapacityUnits: Fn.Ref(ResourceConstants.PARAMETERS.DynamoDBModelTableWriteIOPS)
}
) as any,
}))
}
// If the attribute definition does not exist yet, add it.
const attributeDefinitions = table.Properties.AttributeDefinitions as AttributeDefinition[]
const existingAttribute = attributeDefinitions.find(attr => attr.AttributeName === connectionAttributeName)
if (!existingAttribute) {
attributeDefinitions.push(new AttributeDefinition({
AttributeName: connectionAttributeName,
AttributeType: 'S'
}))
},
{
AttributeName: rangeKey,
AttributeType: 'S',
},
]
: [{ AttributeName: hashKey, AttributeType: 'S' }];
return new DynamoDB.Table({
TableName: this.dynamoDBTableName(typeName),
KeySchema: keySchema,
AttributeDefinitions: attributeDefinitions,
StreamSpecification: {
StreamViewType: 'NEW_AND_OLD_IMAGES',
},
BillingMode: Fn.If(ResourceConstants.CONDITIONS.ShouldUsePayPerRequestBilling, 'PAY_PER_REQUEST', Refs.NoValue),
ProvisionedThroughput: Fn.If(ResourceConstants.CONDITIONS.ShouldUsePayPerRequestBilling, Refs.NoValue, {
ReadCapacityUnits: Fn.Ref(ResourceConstants.PARAMETERS.DynamoDBModelTableReadIOPS),
WriteCapacityUnits: Fn.Ref(ResourceConstants.PARAMETERS.DynamoDBModelTableWriteIOPS),
}) as any,
SSESpecification: {
SSEEnabled: Fn.If(ResourceConstants.CONDITIONS.ShouldUseServerSideEncryption, true, false),
},
PointInTimeRecoverySpecification: Fn.If(
ResourceConstants.CONDITIONS.ShouldUsePointInTimeRecovery,
{
PointInTimeRecoveryEnabled: true,
},
Refs.NoValue
) as any,
...(isSyncEnabled && {
TimeToLiveSpecification: SyncUtils.syncTTLConfig(),
}),
AttributeType: 'S',
},
{
AttributeName: rangeKey,
AttributeType: 'S',
},
]
: [{ AttributeName: hashKey, AttributeType: 'S' }];
return new DynamoDB.Table({
TableName: this.dynamoDBTableName(typeName),
KeySchema: keySchema,
AttributeDefinitions: attributeDefinitions,
StreamSpecification: {
StreamViewType: 'NEW_AND_OLD_IMAGES',
},
BillingMode: Fn.If(ResourceConstants.CONDITIONS.ShouldUsePayPerRequestBilling, 'PAY_PER_REQUEST', Refs.NoValue),
ProvisionedThroughput: Fn.If(ResourceConstants.CONDITIONS.ShouldUsePayPerRequestBilling, Refs.NoValue, {
ReadCapacityUnits: Fn.Ref(ResourceConstants.PARAMETERS.DynamoDBModelTableReadIOPS),
WriteCapacityUnits: Fn.Ref(ResourceConstants.PARAMETERS.DynamoDBModelTableWriteIOPS),
}) as any,
SSESpecification: {
SSEEnabled: Fn.If(ResourceConstants.CONDITIONS.ShouldUseServerSideEncryption, true, false),
},
PointInTimeRecoverySpecification: Fn.If(
ResourceConstants.CONDITIONS.ShouldUsePointInTimeRecovery,
{
PointInTimeRecoveryEnabled: true,
},
Refs.NoValue
) as any,
...(isSyncEnabled && {
TimeToLiveSpecification: SyncUtils.syncTTLConfig(),
private domainName() {
return Fn.If(
ResourceConstants.CONDITIONS.HasEnvironmentParameter,
Refs.NoValue,
Fn.Join(
'-',
[
'd',
Fn.GetAtt(ResourceConstants.RESOURCES.GraphQLAPILogicalID, 'ApiId')
]
)
)
}
private domainName() {
return Fn.If(
ResourceConstants.CONDITIONS.HasEnvironmentParameter,
Refs.NoValue,
Fn.Join('-', ['d', Fn.GetAtt(ResourceConstants.RESOURCES.GraphQLAPILogicalID, 'ApiId')])
);
}