AWS Certified Developer – Associate / Question #686 of 557

Question #686

A developer is creating an AWS Lambda function to process records from an Amazon Kinesis data stream. The developer wants to ensure the function is unit tested as part of its continuous integration and continuous delivery (CI/CD) pipeline.

How can the developer unit test the function?

A

Create a CloudFormation template that provisions a Kinesis stream and deploys the Lambda function. Build the stack during CI/CD, invoke the function, and validate the results.

B

Configure a test Kinesis stream. Use a test that reads records from the stream during the CI/CD process to validate the function's behavior.

C

Integrate a test Kinesis stream into the application's unit tests. Execute these tests during the CI/CD pipeline.

D

Use the AWS lambda invoke command with a simulated Kinesis event payload during the CI/CD process to test the function.

Explanation

Answer D is correct because unit tests should isolate the function's logic from external dependencies like Kinesis streams. The aws lambda invoke command enables testing by simulating a Kinesis event payload, ensuring the function processes records as expected without needing a live stream.

Why other options are incorrect:
- A: Provisioning a Kinesis stream via CloudFormation is integration testing, not unit testing.
- B & C: Using a real Kinesis stream introduces external dependencies, making it integration testing rather than isolated unit testing.

Key Takeaway: Unit tests should mock external services. Simulating event payloads (e.g., Kinesis records) allows validating Lambda logic independently during CI/CD.

Answer

The correct answer is: D