in src/dataServices/dynamoDbDataService.ts [132:159]
private async createResourceWithId(resourceType: string, resource: any, resourceId: string, tenantId?: string) {
const regex = new RegExp('^[a-zA-Z0-9-.]{1,64}$');
if (!regex.test(resourceId)) {
throw new InvalidResourceError(`Resource creation failed, id ${resourceId} is not valid`);
}
const vid = 1;
let resourceClone = clone(resource);
resourceClone.resourceType = resourceType;
const param = DynamoDbParamBuilder.buildPutAvailableItemParam(resourceClone, resourceId, vid, false, tenantId);
try {
await this.dynamoDb.putItem(param).promise();
} catch (e) {
if ((e as any).code === 'ConditionalCheckFailedException') {
// It is highly unlikely that an autogenerated id will collide with a preexisting id.
throw new Error('Resource creation failed, id matches an existing resource');
}
throw e;
}
const item = DynamoDBConverter.unmarshall(param.Item);
resourceClone = DynamoDbUtil.cleanItem(item);
return {
success: true,
message: 'Resource created',
resource: resourceClone,
};
}