Skip to content

Commit

Permalink
Implement distinction for type required in stream
Browse files Browse the repository at this point in the history
  • Loading branch information
fredericbarthelet committed Sep 8, 2020
1 parent 7fd966d commit 26da5e8
Showing 1 changed file with 54 additions and 13 deletions.
67 changes: 54 additions & 13 deletions lib/plugins/aws/package/compile/events/stream/index.js
Expand Up @@ -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 },
Expand Down Expand Up @@ -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'],
},
],
});
}
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 26da5e8

Please sign in to comment.