@kensio/yulin 1.21.8 → 1.21.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/dist/service/lambda/cfn/event-source-mapping/sim-cfn-lambda-event-source-mapping-properties.js +2 -0
  2. package/dist/service/lambda/cfn/event-source-mapping/sim-cfn-lambda-event-source-mapping-property-rules.js +1 -1
  3. package/dist/service/lambda/command/event-source-mapping/create-event-source-mapping-input.d.ts +2 -0
  4. package/dist/service/lambda/command/event-source-mapping/create-event-source-mapping-input.js +4 -0
  5. package/dist/service/lambda/command/event-source-mapping/create-event-source-mapping-refusals.js +0 -5
  6. package/dist/service/lambda/command/event-source-mapping/create-event-source-mapping.handler.d.ts +2 -0
  7. package/dist/service/lambda/command/event-source-mapping/create-event-source-mapping.handler.js +2 -0
  8. package/dist/service/lambda/command/event-source-mapping/sim-lambda-event-source-mapping-commands.d.ts +2 -0
  9. package/dist/service/lambda/destination/sim-lambda-destination-targets.d.ts +2 -1
  10. package/dist/service/lambda/event-source/poll/kinesis/sim-lambda-kinesis-shard-poller.d.ts +0 -4
  11. package/dist/service/lambda/event-source/poll/kinesis/sim-lambda-kinesis-shard-poller.js +10 -15
  12. package/dist/service/lambda/event-source/poll/sim-lambda-dynamodb-stream-event-source-poller.d.ts +1 -6
  13. package/dist/service/lambda/event-source/poll/sim-lambda-dynamodb-stream-event-source-poller.js +9 -27
  14. package/dist/service/lambda/event-source/poll/sim-lambda-dynamodb-stream-polling.d.ts +19 -0
  15. package/dist/service/lambda/event-source/poll/sim-lambda-dynamodb-stream-polling.js +27 -0
  16. package/dist/service/lambda/event-source/poll/sim-lambda-event-source-function.d.ts +1 -1
  17. package/dist/service/lambda/event-source/poll/sim-lambda-event-source-function.js +3 -1
  18. package/dist/service/lambda/event-source/poll/sim-lambda-stream-batch-age.d.ts +13 -0
  19. package/dist/service/lambda/event-source/poll/sim-lambda-stream-batch-age.js +27 -0
  20. package/dist/service/lambda/event-source/poll/sim-lambda-stream-batch-info.d.ts +15 -0
  21. package/dist/service/lambda/event-source/poll/sim-lambda-stream-batch-info.js +26 -0
  22. package/dist/service/lambda/event-source/poll/sim-lambda-stream-batch-outcome.d.ts +1 -0
  23. package/dist/service/lambda/event-source/poll/sim-lambda-stream-batch-outcome.js +7 -1
  24. package/dist/service/lambda/event-source/poll/sim-lambda-stream-batch-processing.d.ts +17 -0
  25. package/dist/service/lambda/event-source/poll/sim-lambda-stream-batch-processing.js +12 -0
  26. package/dist/service/lambda/event-source/poll/sim-lambda-stream-cursor.d.ts +15 -0
  27. package/dist/service/lambda/event-source/poll/sim-lambda-stream-cursor.js +28 -0
  28. package/dist/service/lambda/event-source/poll/sim-lambda-stream-expiry.d.ts +19 -0
  29. package/dist/service/lambda/event-source/poll/sim-lambda-stream-expiry.js +23 -0
  30. package/dist/service/lambda/event-source/poll/sim-lambda-stream-failure-context.d.ts +3 -0
  31. package/dist/service/lambda/event-source/poll/sim-lambda-stream-failure-context.js +19 -0
  32. package/dist/service/lambda/event-source/poll/sim-lambda-stream-failure-destination.d.ts +15 -0
  33. package/dist/service/lambda/event-source/poll/sim-lambda-stream-failure-destination.js +38 -0
  34. package/dist/service/lambda/event-source/poll/sim-lambda-stream-failure-record.d.ts +41 -0
  35. package/dist/service/lambda/event-source/poll/sim-lambda-stream-failure-record.js +17 -0
  36. package/dist/service/lambda/event-source/poll/sim-lambda-stream-progress-state.d.ts +21 -0
  37. package/dist/service/lambda/event-source/poll/sim-lambda-stream-progress-state.js +39 -0
  38. package/dist/service/lambda/event-source/poll/sim-lambda-stream-progress.d.ts +7 -37
  39. package/dist/service/lambda/event-source/poll/sim-lambda-stream-progress.js +22 -62
  40. package/dist/service/lambda/event-source/poll/sim-lambda-stream-retry.d.ts +4 -39
  41. package/dist/service/lambda/event-source/poll/sim-lambda-stream-retry.js +12 -64
  42. package/dist/service/lambda/event-source/sim-lambda-event-source-mapping.d.ts +10 -3
  43. package/dist/service/lambda/event-source/sim-lambda-event-source-mapping.js +12 -3
  44. package/dist/service/lambda/event-source/sim-lambda-stream-destination-config.d.ts +7 -0
  45. package/dist/service/lambda/event-source/sim-lambda-stream-destination-config.js +38 -0
  46. package/dist/service/lambda/event-source/stream/kinesis/sim-kinesis-event-source-streams.js +1 -0
  47. package/dist/service/lambda/event-source/stream/sim-dynamodb-event-source-stream-reader.js +1 -0
  48. package/dist/service/lambda/event-source/stream/sim-dynamodb-event-source-stream-shard.d.ts +1 -0
  49. package/dist/service/lambda/event-source/stream/sim-dynamodb-event-source-stream-shard.js +7 -0
  50. package/dist/service/lambda/event-source/stream/sim-lambda-event-source-streams.d.ts +1 -0
  51. package/dist/service/lambda/index.d.ts +1 -0
  52. package/dist/service/lambda/sim-lambda-commands.js +1 -0
  53. package/docs/services/lambda/README.md +59 -6
  54. package/package.json +1 -1
@@ -40,6 +40,7 @@ export class SimKinesisEventSourceStreams {
40
40
  }, { caller });
41
41
  return {
42
42
  records: output.Records,
43
+ shardId: request.shardId,
43
44
  next: { kind: "iterator", shardIterator: output.NextShardIterator },
44
45
  drained: false,
45
46
  };
@@ -29,6 +29,7 @@ export class SimDynamoDbEventSourceStreamReader {
29
29
  const next = output.NextShardIterator;
30
30
  return {
31
31
  records: output.Records ?? [],
32
+ shardId: await this.shard.shardId(request),
32
33
  next: simDynamoDbEventSourceNextPosition(next, position),
33
34
  drained: next === undefined,
34
35
  };
@@ -23,5 +23,6 @@ export declare class SimDynamoDbEventSourceStreamShard {
23
23
  * is the shard.
24
24
  */
25
25
  iteratorFor(request: SimLambdaEventSourceStreamRequest, position: SimLambdaEventSourceStreamNamedPosition): Promise<string>;
26
+ shardId(request: SimLambdaEventSourceStreamRequest): Promise<string>;
26
27
  private describe;
27
28
  }
@@ -49,6 +49,13 @@ export class SimDynamoDbEventSourceStreamShard {
49
49
  }
50
50
  return iterator.ShardIterator;
51
51
  }
52
+ async shardId(request) {
53
+ const description = await this.describe(request);
54
+ const shardId = description.Shards?.[0]?.ShardId;
55
+ if (shardId === undefined)
56
+ refuse(request, "reports no shard to read records from");
57
+ return shardId;
58
+ }
52
59
  async describe(request) {
53
60
  const { caller, streamArn } = request;
54
61
  const described = await this.commands.describeStream({ input: { StreamArn: streamArn } }, { caller });
@@ -84,6 +84,7 @@ export interface SimLambdaEventSourceStreamReadRequest extends SimLambdaEventSou
84
84
  export interface SimLambdaEventSourceStreamProgressBatch {
85
85
  readonly next: SimLambdaEventSourceStreamPosition;
86
86
  readonly drained: boolean;
87
+ readonly shardId?: string;
87
88
  }
88
89
  /**
89
90
  * What one read of a DynamoDB stream came back with.
@@ -16,3 +16,4 @@ export type { SimLambdaDynamoDbAttributeValue, SimLambdaDynamoDbImage, } from ".
16
16
  export { SimLambdaStreamCascadeError } from "./event-source/stream/sim-lambda-stream-cascade.error.js";
17
17
  export type { SimLambdaDestinationRecord, SimLambdaDestinationRequestContext, SimLambdaDestinationResponseContext, } from "./destination/sim-lambda-destination-record.js";
18
18
  export type { SimLambdaInvocationCondition } from "./function/event-invoke/sim-lambda-event-invoke-config.js";
19
+ export type { SimLambdaStreamFailureRecord, SimLambdaStreamFailureCondition, } from "./event-source/poll/sim-lambda-stream-failure-record.js";
@@ -113,6 +113,7 @@ export class SimLambdaCommands {
113
113
  background,
114
114
  });
115
115
  this.eventSourceMappings = new SimLambdaEventSourceMappingCommands({
116
+ destinations,
116
117
  accountRegionScope,
117
118
  pollers: new SimLambdaEventSourcePollers({
118
119
  functions: this.functionLookup,
@@ -1904,7 +1904,7 @@ with more steps.
1904
1904
  `MaximumRetryAttempts` and `MaximumRecordAgeInSeconds` govern the same failed-batch lifecycle, and a
1905
1905
  stream mapping keeps both. `MaximumRetryAttempts: 0` makes one delivery and no retries, and a
1906
1906
  positive value allows that many retries after the first delivery. `MaximumRecordAgeInSeconds`
1907
- discards a record once the next attempt would fall past that age. Lambda's `-1` means no limit
1907
+ discards expired records before each invocation, including the first poll. Lambda's `-1` means no limit
1908
1908
  (that is what a mapping naming neither reports back).
1909
1909
 
1910
1910
  ```typescript sim-lambda-stream-retry-limits
@@ -2033,6 +2033,58 @@ discarded, and the mapping reads on from behind it.
2033
2033
  10,000 retries, `-1` to 604,800 seconds) is a `ValidationException`. A queue mapping takes neither,
2034
2034
  because a message the handler never takes is left to the queue's own redrive policy.
2035
2035
 
2036
+ ### Sending discarded stream batches to a destination
2037
+
2038
+ DynamoDB Streams and Kinesis mappings accept `DestinationConfig.OnFailure` with a standard SQS
2039
+ queue or SNS topic ARN. Supply it to `CreateEventSourceMapping` or the
2040
+ `AWS::Lambda::EventSourceMapping` resource alongside the retry and record-age limits:
2041
+
2042
+ ```json
2043
+ {
2044
+ "MaximumRetryAttempts": 10,
2045
+ "MaximumRecordAgeInSeconds": 3600,
2046
+ "DestinationConfig": {
2047
+ "OnFailure": {
2048
+ "Destination": "arn:aws:sqs:eu-west-2:111111111111:stream-failures"
2049
+ }
2050
+ }
2051
+ }
2052
+ ```
2053
+
2054
+ CDK's `DynamoEventSource` and `KinesisEventSource` accept `onFailure: new SqsDlq(queue)` or
2055
+ `onFailure: new SnsDlq(topic)`. Their synthesized destination configuration is passed through to
2056
+ the simulated mapping. Create, Get, List and Delete responses preserve that configuration.
2057
+
2058
+ The function's execution role needs `sqs:SendMessage` on the queue or `sns:Publish` on the topic.
2059
+ Delivery goes through the simulated destination service, so its IAM checks and SNS subscriptions
2060
+ apply. An IAM denial or a missing destination rejects `backgroundTasksComplete()` or the clock
2061
+ advance that exhausted the batch. The discarded records have already advanced the checkpoint.
2062
+ Yulin attempts destination delivery once and does not retry a failed send.
2063
+
2064
+ The JSON message follows the AWS
2065
+ [DynamoDB Streams](https://docs.aws.amazon.com/lambda/latest/dg/services-dynamodb-errors.html) and
2066
+ [Kinesis](https://docs.aws.amazon.com/lambda/latest/dg/kinesis-on-failure-destination.html)
2067
+ notification formats. Import `SimLambdaStreamFailureRecord` from `@kensio/yulin/lambda` to type it.
2068
+
2069
+ - `version` is `"1.0"` and `timestamp` is the simulated discard time in ISO 8601 format.
2070
+ - `requestContext` contains a generated `requestId`, the mapping's `functionArn`,
2071
+ `approximateInvokeCount`, and either `RetryAttemptsExhausted` or `RecordAgeExceeded` as `condition`.
2072
+ - `responseContext` reports `statusCode: 200` and `executedVersion`. A handler error adds
2073
+ `functionError: "Unhandled"`. A valid partial-batch failure response leaves that field out.
2074
+ Records discarded before any invocation omit `responseContext`.
2075
+ - `DDBStreamBatchInfo` or `KinesisBatchInfo` identifies the stream ARN, shard ID, first and last
2076
+ sequence numbers, first and last arrival times, and batch size. Arrival times are ISO 8601 strings.
2077
+
2078
+ The original record payloads are absent. A successful batch produces no notification. After a
2079
+ partial-batch response, the notification covers the discarded suffix starting at the failed
2080
+ checkpoint. When only an older prefix expires, its notification excludes the younger records.
2081
+ Records already expired on their first poll report zero invocations. Request IDs are generated for
2082
+ the notification and are not correlated with the handler's invocation context.
2083
+
2084
+ S3 destinations, FIFO queues or topics, and `OnSuccess` are refused. SQS source mappings cannot
2085
+ have this destination configuration. The simulator's existing five-retry cap for mappings with
2086
+ neither limit also produces a failure notification when it discards a batch.
2087
+
2036
2088
  ### Reporting individual record failures
2037
2089
 
2038
2090
  A stream mapping with `FunctionResponseTypes: ["ReportBatchItemFailures"]` reads the handler's
@@ -2273,8 +2325,7 @@ the three stream actions on the stream ARN and `dynamodb:ListStreams` on every s
2273
2325
  the mapping's execution-role check is looking for.
2274
2326
 
2275
2327
  The properties a non-default `DynamoEventSource` adds are refused by name. Those are
2276
- `FilterCriteria`, `ParallelizationFactor`, `BisectBatchOnFunctionError`, `TumblingWindowInSeconds`
2277
- and `DestinationConfig`.
2328
+ `FilterCriteria`, `ParallelizationFactor`, `BisectBatchOnFunctionError` and `TumblingWindowInSeconds`.
2278
2329
 
2279
2330
  A hand-written template or a SAM application usually gives the function the AWS managed policy
2280
2331
  `AWSLambdaDynamoDBExecutionRole` instead. Simulated IAM has no model for managed policy ARNs, so
@@ -4154,8 +4205,10 @@ Current documented limitations:
4154
4205
  - Throttling does not drive a retry. A retry follows a handler that threw or ran out of time, and
4155
4206
  the `MaximumEventAgeInSeconds` a config carries is measured from when the invocation was
4156
4207
  accepted.
4157
- - `DestinationConfig` on an event source mapping is left out. It is a different mechanism from the
4158
- asynchronous invocation destinations above.
4208
+ - Stream mappings support standard SQS and SNS `DestinationConfig.OnFailure` destinations.
4209
+ S3 destinations and `OnSuccess` are refused. Destination delivery is attempted once. A delivery
4210
+ failure rejects the background task after the discarded records have advanced the checkpoint.
4211
+ Destination delivery retries and `DestinationDeliveryFailures` metrics are not simulated.
4159
4212
  - A settings change takes effect at once. Real Lambda reports `LastUpdateStatus: "InProgress"` while
4160
4213
  it rolls the change out, and neither that member nor the wait it implies is simulated.
4161
4214
  - A cross-account grant is only half of what admits a call. The caller's own Account has to allow
@@ -4245,7 +4298,7 @@ Current documented limitations:
4245
4298
  it stands.
4246
4299
  - SQS queues, DynamoDB streams and Kinesis streams are the only event sources. Kafka, DocumentDB and
4247
4300
  Kinesis enhanced fan-out consumers are refused outright, and so are `FilterCriteria`,
4248
- `ScalingConfig`, `DestinationConfig`, `BisectBatchOnFunctionError`, `ParallelizationFactor`,
4301
+ `ScalingConfig`, `BisectBatchOnFunctionError`, `ParallelizationFactor`,
4249
4302
  `TumblingWindowInSeconds` and the other mapping inputs this simulation has no behaviour for. An
4250
4303
  `AWS::Lambda::EventSourceMapping` carrying `Tags` is the exception, and deploys with the tags
4251
4304
  dropped and the property recorded.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kensio/yulin",
3
- "version": "1.21.8",
3
+ "version": "1.21.9",
4
4
  "description": "AWS system behaviour simulation for isolated unit testing",
5
5
  "repository": "https://github.com/KensioSoftware/yulin",
6
6
  "homepage": "https://yulinsim.dev/",