From 26da5e8c1f84c1b1f7928251cdbc4bc3fecfa20d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Barthelet?= Date: Tue, 8 Sep 2020 13:42:36 +0200 Subject: [PATCH] Implement distinction for type required in stream --- .../package/compile/events/stream/index.js | 67 +++++++++++++++---- 1 file changed, 54 insertions(+), 13 deletions(-) diff --git a/lib/plugins/aws/package/compile/events/stream/index.js b/lib/plugins/aws/package/compile/events/stream/index.js index a51a1628afec..91850f153b7b 100644 --- a/lib/plugins/aws/package/compile/events/stream/index.js +++ b/lib/plugins/aws/package/compile/events/stream/index.js @@ -17,7 +17,7 @@ class AwsCompileStreamEvents { { type: 'object', properties: { - arn: { $ref: '#/definitions/awsArn' }, + arn: { $ref: '#/definitions/awsArnString' }, type: { enum: ['dynamodb', 'kinesis'] }, batchSize: { type: 'integer', minimum: 1, maximum: 10000 }, parallelizationFactor: { type: 'integer', minimum: 1, maximum: 10 }, @@ -67,6 +67,59 @@ class AwsCompileStreamEvents { additionalProperties: false, required: ['arn'], }, + { + type: 'object', + properties: { + arn: { $ref: '#/definitions/awsCfFunction' }, + type: { enum: ['dynamodb', 'kinesis'] }, + batchSize: { type: 'integer', minimum: 1, maximum: 10000 }, + parallelizationFactor: { type: 'integer', minimum: 1, maximum: 10 }, + startingPosition: { enum: ['LATEST', 'TRIM_HORIZON'] }, + enabled: { type: 'boolean' }, + consumer: { oneOf: [{ const: true }, { $ref: '#/definitions/awsArn' }] }, + batchWindow: { type: 'integer', minimum: 0, maximum: 300 }, + maximumRetryAttempts: { type: 'integer', minimum: -1, maximum: 10000 }, + bisectBatchOnFunctionError: { type: 'boolean' }, + maximumRecordAgeInSeconds: { + oneOf: [ + { type: 'integer', minimum: -1, maximum: -1 }, + { type: 'integer', minimum: 60, maximum: 604800 }, + ], + }, + destinations: { + type: 'object', + properties: { + onFailure: { + anyOf: [ + { $ref: '#/definitions/awsArnString' }, + { + type: 'object', + properties: { + arn: { $ref: '#/definitions/awsArnString' }, + type: { enum: ['sns', 'sqs'] }, + }, + additionalProperties: false, + required: ['arn'], + }, + { + type: 'object', + properties: { + arn: { $ref: '#/definitions/awsCfFunction' }, + type: { enum: ['sns', 'sqs'] }, + }, + additionalProperties: false, + required: ['arn', 'type'], + }, + ], + }, + }, + additionalProperties: false, + required: ['onFailure'], + }, + }, + additionalProperties: false, + required: ['arn', 'type'], + }, ], }); } @@ -131,18 +184,6 @@ class AwsCompileStreamEvents { let Enabled = true; if (typeof event.stream === 'object') { - if (typeof event.stream.arn !== 'string') { - // for dynamic arns (GetAtt/ImportValue) - if (!event.stream.type) { - const errorMessage = [ - `Missing "type" property for stream event in function "${functionName}"`, - ' If the "arn" property on a stream is a complex type (such as Fn::GetAtt)', - ' then a "type" must be provided for the stream, either "kinesis" or,', - ' "dynamodb". Please check the docs for more info.', - ].join(''); - throw new this.serverless.classes.Error(errorMessage); - } - } EventSourceArn = event.stream.arn; BatchSize = event.stream.batchSize || BatchSize; if (event.stream.parallelizationFactor) {