# AWS Lambda with PowerTools and SecretsManager Integration This pattern creates an AWS Lambda function to call a protected API endpoint. It is integrated with AWS SecretsManager via Lambda PowerTools, and is deployed with the AWS Cloud Development Kit (AWS CDK) in Python. It includes a test API Gateway deployment to aid in both demonstration and testing. The sample application was developed in Python. ## Requirements * [Create an AWS account](https://portal.aws.amazon.com/gp/aws/developer/registration/index.html) if you do not already have one and log in. The IAM user that you use must have sufficient permissions to make necessary AWS service calls and manage AWS resources. * [AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html) installed and configured * [Git Installed](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git) * [AWS CDK Toolkit](https://docs.aws.amazon.com/cdk/latest/guide/cli.html) installed and configured * [Python 3.9+](https://www.python.org/downloads/) installed ## Deployment Instructions 1. Create a new directory, navigate to that directory in a terminal and clone the GitHub repository: ``` git clone https://github.com/aws-samples/serverless-patterns ``` 1. Change directory to the pattern directory: ``` cd serverless-patterns/lambda-powertools-secretsmanager-cdk/src ``` 1. Create a virtual environment for Python: ``` python3 -m venv .venv ``` 1. Activate the virtual environment: ```bash source .venv/bin/activate ``` For a Windows platform, activate the virtualenv like this: ``` .venv\Scripts\activate.bat ``` 1. Install the Python required dependencies: ``` pip install -r requirements.txt ``` 1. From the command line, use AWS CDK to deploy the AWS resources for the pattern as specified in the app.py file: ``` cdk synth cdk deploy --all ``` 1. Note the outputs from the CDK deployment process. This will contain the deployed Lambda function URL. ## How it works The deployed Lambda function uses [Lambda Powertools](https://awslabs.github.io/aws-lambda-powertools-python/2.5.0/) to query AWS SecretsManager for an API key. This API key is then used to invoke an API endpoint using [urllib3](https://urllib3.readthedocs.io/en/stable/index.html). ## Testing Paste the Lambda function URL that is generated by CDK Deploy into your web browser. This endpoint is public for testing and verification purposes only. Make sure to secure/remove the endpoint if using in production systems. ## Cleanup 1. Delete the stack ```bash cdk destroy --all ``` ---- Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved. SPDX-License-Identifier: MIT-0