Exploring AWS Serverless Deployments with CDK vFrom RSS to X Posts - Part f the Odyssey

王林
Release: 2024-08-02 10:21:41
Original
1122 people have browsed it

Exploring AWS Serverless Deployments with CDK vFrom RSS to X Posts - Part f the Odyssey

Welcome to part 3 of “Exploring AWS Serverless Deployments with CDK v2”. Firstly I’d like to thank you for your patience as there’s been a bit of a gap since part 2. I was deep into studying and working on serverless projects at work which kept me away, but i’m excited to get back on track and continue our exploration.

In previous posts, we’ve defined our constructs and deployed them to AWS. Today, we’ll focus on an essential practice: testing. Proper testing ensures that our deployments work as expected and can save us from potential issues.

Getting Started With Testing

To get started, you’ll need to add pytest to your project’s dependencies (the main requirements.txt file for our stack).

pip install -r requirements.txt
Copy after login

Within our project, navigate towards the test directory, then unit and open the test_rss_lambda_ddb_socialshare_stack.py file. This auto generated test file includes an example test.

We don’t have an SQS construct in our stack but reviewing the example test provides some level of insight on how to test a construct. Let’s delete the auto generated example test and create our own test.

Setting Up The Testing Function

First, let’s create a reusable function to get the CloudFormation template from the stack:

Testing DynamoDB Table Properties

We’ll start by adding a test to check that the DynamoDB table in our stack has the correct properties. Here’s how to do it:

Testing Lambda Functions

Next, let’s ensure that our stack creates the correct number of Lambda functions and verifies their runtime version:

Running Tests

To run tests you can execute pytest in the terminal:

pytest
Copy after login

Below is the output you should receive:

================================================================================= test session starts =================================================================================
platform darwin -- Python 3.12.4, pytest-8.1.1, pluggy-1.4.0
rootdir: /Users/adrian/Developer/Projects/rss-lambda-ddb-socialshare
plugins: typeguard-2.13.3
collected 2 items                                                                                                                                                                     

tests/unit/test_rss_lambda_ddb_socialshare_stack.py ..                                                                                                                          [100%]

================================================================================= 2 passed in 21.86s ==================================================================================
Copy after login

Conclusion

In Part 3 of our series, we’ve learned how to test our CDK constructs. In the final installment, we will explore how to test Lambda functions locally.

Resources

  • Pytest
  • Testing constructs

The above is the detailed content of Exploring AWS Serverless Deployments with CDK vFrom RSS to X Posts - Part f the Odyssey. For more information, please follow other related articles on the PHP Chinese website!

source:dev.to
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!