generated from amazon-archives/__template_MIT-0
-
Notifications
You must be signed in to change notification settings - Fork 1k
New serverless pattern - API Gateway - Lambda - Redshift Data API #2487
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
julianwood
merged 9 commits into
aws-samples:main
from
klmuthu:klmuthu-feature-apigw-lambda-redshiftdataapi
Jan 6, 2025
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
10f54cc
initial commit for api gateway-lambda-redshift integration pattern
39dfdfd
updated readme with cdk commands
da3c0f7
updated readme with cdk commands
e22b36b
added example-pattern.json
b3e67a4
lambda fixes
d277c85
updates to readme
687b073
Update README.md
ellisms 9c44783
publishing file
ellisms 667ca50
tagging
ellisms File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| *.swp | ||
| package-lock.json | ||
| __pycache__ | ||
| .pytest_cache | ||
| .venv | ||
| *.egg-info | ||
|
|
||
| # CDK asset staging directory | ||
| .cdk.staging | ||
| cdk.out |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| # Amazon Redshift Data API with Amazon API Gateway | ||
|
|
||
| This pattern demonstrates how to expose data from Redshift through API using API Gateway, Lambda and Redshift Data API. | ||
|
|
||
| Learn more about this pattern at [Serverless Land Patterns](https://serverlessland.com/patterns/apigw-lambda-redshiftdataapi) | ||
|
|
||
| Important: this application uses various AWS services and there are costs associated with these services after the Free Tier usage - please see the [AWS Pricing page](https://aws.amazon.com/pricing/) for details. You are responsible for any AWS costs incurred. No warranty is implied in this example. | ||
|
|
||
| ## 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 installed](https://docs.aws.amazon.com/cdk/latest/guide/cli.html) | ||
| - [Python 3 installed](https://www.python.org/downloads/) | ||
klmuthu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| - [pipenv installed](https://pipenv.pypa.io/en/latest/installation.html) | ||
| - [Create Redshift Serverless](https://docs.aws.amazon.com/redshift/latest/gsg/new-user-serverless.html#serverless-console-resource-creation) | ||
|
|
||
| ## 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 apigw-lambda-redshiftdataapi | ||
| ``` | ||
| 1. Create python virtual environment and install dependencies: | ||
| ``` | ||
| python3 -m venv venv | ||
| source ./venv/bin/activate | ||
| pipenv install | ||
| pipenv install -r requirements.txt | ||
| ``` | ||
| 1. Create .env file to include Redshift cluster environment variables: | ||
| ``` | ||
| Create a .env file in the cloned directory | ||
| Add the following variables with respective to values | ||
| REDSHIFT_CLUSTER_ARN=arn:aws:redshift-serverless:<region>:<accountid>:workgroup/<workgroupid> | ||
| REDSHIFT_WORKGROUP=<workgroup-name> | ||
| REDSHIFT_DATABASE=<database-name> | ||
| ``` | ||
| 1. From the command line, use AWS CDK to deploy the AWS resources for the pattern as specified in the template.yml file: | ||
|
|
||
| ``` | ||
| cdk deploy --app "python3 apigw_lambda_redshiftdataapi_stack.py" | ||
| ``` | ||
|
|
||
| 1. Note the outputs from the CDK deployment process. These contain the resource names and/or ARNs which are used for testing. | ||
|
|
||
| ## How it works | ||
|
|
||
| This setup orchestrates exposing data from Redshift through API Gateway with Cognito authorizer and Lambda using Redshift Data API. | ||
|
|
||
| ## Testing | ||
|
|
||
| 1. Use an api client with oauth capability such as Postman or Rapid API to test the api. API url can be found from CDK stack deployment output ApigwRedshiftDataApi.ApiUrl. You will need to login to AWS Console, navigate to Cognito app client and retrieve the client id and secret to pass it in the api call. | ||
|
|
||
| ## Cleanup | ||
|
|
||
| cdk destroy --app "python3 apigw_lambda_redshiftdataapi_stack.py" | ||
|
|
||
| --- | ||
|
|
||
| Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
|
|
||
| SPDX-License-Identifier: MIT-0 | ||
87 changes: 87 additions & 0 deletions
87
apigw-lambda-redshiftdataapi/apigw-lambda-redshiftapi.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| { | ||
| "title": "Amazon Reshift Data API with Amazon API Gateway and AWS Lambda", | ||
| "description": "Access data from Redshift with API Gateway, Lambda and Redshift Data API", | ||
| "language": "Python", | ||
| "level": "200", | ||
| "framework": "CDK", | ||
| "introBox": { | ||
| "headline": "How it works", | ||
| "text": [ | ||
| "This sample project demonstrates how to expose data from Redshift through API using API Gateway, Lambda and Redshift Data API.", | ||
| "Implemented in CDK." | ||
| ] | ||
| }, | ||
| "gitHub": { | ||
| "template": { | ||
| "repoURL": "https://github.com/aws-samples/serverless-patterns/tree/main/apigw-lambda-redshiftdataapi", | ||
| "templateURL": "serverless-patterns/apigw-lambda-redshiftdataapi", | ||
| "projectFolder": "apigw-lambda-redshiftdataapi", | ||
| "templateFile": "apigw_lambda_redshiftdataapi_stack.py" | ||
| } | ||
| }, | ||
| "resources": { | ||
| "bullets": [ | ||
| { | ||
| "text": "Redshift Data API", | ||
| "link": "https://docs.aws.amazon.com/redshift/latest/mgmt/data-api.html" | ||
| }, | ||
| { | ||
| "text": "API Gateway", | ||
| "link": "https://docs.aws.amazon.com/apigateway/latest/developerguide/welcome.html" | ||
| } | ||
| ] | ||
| }, | ||
| "deploy": { | ||
| "text": [ | ||
| "See the GitHub repo for detailed deployment instructions." | ||
| ] | ||
| }, | ||
| "testing": { | ||
| "text": [ | ||
| "See the GitHub repo for detailed testing instructions." | ||
| ] | ||
| }, | ||
| "cleanup": { | ||
| "text": [ | ||
| "Delete the stack: <code>cdk deploy --app \"python3 apigw_lambda_redshiftdataapi_stack.py\"</code>." | ||
| ] | ||
| }, | ||
| "authors": [ | ||
| { | ||
| "name": "Muthu Kumar", | ||
| "image": "https://avatars.githubusercontent.com/u/51725180", | ||
| "bio": "AWS Solutions Architect. Serverless advocate and enthusiast.", | ||
| "linkedin": "klmuthu" | ||
| } | ||
| ], | ||
| "patternArch": { | ||
| "icon1": { | ||
| "x": 20, | ||
| "y": 50, | ||
| "service": "apigw", | ||
| "label": "API Gateway REST API" | ||
| }, | ||
| "icon2": { | ||
| "x": 50, | ||
| "y": 50, | ||
| "service": "lambda", | ||
| "label": "AWS Lambda" | ||
| }, | ||
| "icon3": { | ||
| "x": 80, | ||
| "y": 50, | ||
| "service": "redshift", | ||
| "label": "Amazon Redshift" | ||
| }, | ||
| "line1": { | ||
| "from": "icon1", | ||
| "to": "icon2", | ||
| "label": "Request" | ||
| }, | ||
| "line2": { | ||
| "from": "icon2", | ||
| "to": "icon3", | ||
| "label": "Redshift Data API" | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.