Skip to content

Commit

Permalink
Implement distinction for type required in event
Browse files Browse the repository at this point in the history
  • Loading branch information
fredericbarthelet committed Sep 11, 2020
1 parent f295ea1 commit dc92b20
Showing 1 changed file with 27 additions and 23 deletions.
50 changes: 27 additions & 23 deletions lib/plugins/aws/package/compile/events/stream/index.js
Expand Up @@ -42,20 +42,23 @@ class AwsCompileStreamEvents {
{
type: 'object',
properties: {
arn: { $ref: '#/definitions/awsArnString' },
arn: { $ref: '#/definitions/awsArn' },
type: { enum: ['sns', 'sqs'] },
},
additionalProperties: false,
required: ['arn'],
},
{
type: 'object',
properties: {
arn: { $ref: '#/definitions/awsCfFunction' },
type: { enum: ['sns', 'sqs'] },
},
additionalProperties: false,
required: ['arn', 'type'],
oneOf: [
{
properties: {
arn: { $ref: '#/definitions/awsCfFunction' },
},
required: ['type'],
},
{
properties: {
arn: { $ref: '#/definitions/awsArnString' },
},
},
],
},
],
},
Expand All @@ -66,6 +69,19 @@ class AwsCompileStreamEvents {
},
additionalProperties: false,
required: ['arn'],
oneOf: [
{
properties: {
arn: { $ref: '#/definitions/awsCfFunction' },
},
required: ['type'],
},
{
properties: {
arn: { $ref: '#/definitions/awsArnString' },
},
},
],
},
],
});
Expand Down Expand Up @@ -131,18 +147,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 dc92b20

Please sign in to comment.