Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions python-test-samples/apigw-lambda/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[![python: 3.9](https://img.shields.io/badge/Python-3.9-green)](https://img.shields.io/badge/Python-3.9-green)
[![python: 3.13](https://img.shields.io/badge/Python-3.13-green)](https://img.shields.io/badge/Python-3.13-green)
[![AWS: Lambda](https://img.shields.io/badge/AWS-Lambda-blueviolet)](https://img.shields.io/badge/AWS-Lambda-blueviolet)
[![test: unit](https://img.shields.io/badge/Test-Unit-blue)](https://img.shields.io/badge/Test-Unit-blue)
[![test: integration](https://img.shields.io/badge/Test-Integration-yellow)](https://img.shields.io/badge/Test-Integration-yellow)
Expand Down Expand Up @@ -45,7 +45,7 @@ The SAM CLI extends the AWS CLI that adds functionality for building and testing
To use the SAM CLI, you need the following tools.

* SAM CLI - [Install the SAM CLI](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html)
* Python 3 - [Install Python 3](https://www.python.org/downloads/)
* Python 3.13 - [Install Python 3.13](https://www.python.org/downloads/)
* Docker - [Install Docker community edition](https://hub.docker.com/search/?type=edition&offering=community)

[[top]](#python-test-samples-project)
Expand Down Expand Up @@ -172,11 +172,15 @@ The project uses the [moto](http://docs.getmoto.org/en/latest/) dependency libra
# Create and Activate a Python Virtual Environment

pip3 install virtualenv
python3 -m venv venv
python3 -m virtualenv venv
source ./venv/bin/activate

# install dependencies
# Verify Python version (Should show Python 3.13.x)

python3 --version
pip3 --version

# install dependencies
pip3 install -r tests/requirements.txt

# run unit tests with mocks
Expand All @@ -202,7 +206,7 @@ The `AWS CLI` enables you to invoke a Lambda function in the cloud.
```shell
# invoke a Lambda function in the cloud using the AWS CLI. Substitute the function name as created in your stack.

aws lambda invoke --function-name apigw-lambda-PythonTestDemo-6Ecinx8IauZv outfile.txt
aws lambda invoke --function-name apigw-lambda-PythonTestDemo-XlkJiaHvJn1t outfile.txt
```
[[top]](#python-test-samples-project)

Expand All @@ -218,7 +222,7 @@ sam logs -n PythonTestDemo --stack-name apigw-lambda --tail
In a new terminal, curl the API Gateway and watch the log output.

```shell
curl <API Gateway url>
curl https://<API Gateway deploy>.execute-api.eu-west-1.amazonaws.com/Prod/hello
```

You can find more information and examples about filtering Lambda function logs in the [SAM CLI Documentation](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-logging.html).
Expand Down
2 changes: 1 addition & 1 deletion python-test-samples/apigw-lambda/template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Resources:
Resource: 'arn:aws:s3:::*'
CodeUri: src/
Handler: app.lambda_handler
Runtime: python3.9
Runtime: python3.13
Architectures:
- x86_64
Events:
Expand Down
8 changes: 4 additions & 4 deletions python-test-samples/apigw-lambda/tests/unit/mock_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from urllib import response
import boto3
import pytest
from moto import mock_s3
from moto import mock_aws # Changed from mock_s3
from aws_lambda_powertools.utilities.data_classes import APIGatewayProxyEvent
from src import app

Expand All @@ -16,11 +16,11 @@ def apigw_event() -> APIGatewayProxyEvent:
return APIGatewayProxyEvent(json.load(f))


@mock_s3
@mock_aws # Changed from @mock_s3
def test_lambda_handler(apigw_event: dict) -> None:

# set up test bucket
s3_client = boto3.client('s3')
s3_client = boto3.client('s3', region_name='us-east-1') # Added region for consistency
test_bucket_names = ["test_bucket1","test_bucket2"]
test_data = b'col_1,col_2\n1,2\n3,4\n'
for test_bucket_name in test_bucket_names:
Expand All @@ -35,4 +35,4 @@ def test_lambda_handler(apigw_event: dict) -> None:
assert test_response["statusCode"] == 200
assert test_bucket_names[0] in test_response_data
assert test_bucket_names[1] in test_response_data
assert len(test_response_data) == 2
assert len(test_response_data) == 2