Skip to content
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

[New Pattern] AWS Lambda to Amazon Aurora Serverless #2664

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
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
3 changes: 3 additions & 0 deletions terraform-lambda-aurora-serverless/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
builds/*
.terraform
.terraform.*
49 changes: 49 additions & 0 deletions terraform-lambda-aurora-serverless/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# AWS Lambda function to Amazon Aurora Serverless

The pattern creates a Lambda function and a Amazon Aurora Serverless cluster, a Log group and the IAM resources required to run the application.

The Lambda function is written in Python that uses pymysql client to establish connectivity with the serverless database.

## Getting started with Terraform Serverless Patterns

Read more about general requirements and deployment instructions for Terraform Serverless Patterns [here](https://github.com/aws-samples/serverless-patterns/blob/main/terraform-fixtures/docs/README.md).

## Steps

First of all, you will need to install the 'pymysql' client depedency which is used in the Lambda function code.
```shell
cd src/function
pip3 install -r requirements.txt -t .
cd ../..
```
Then perform the following terraform commands to deploy the stack
```shell
terraform init
terrform deploy
```

## Testing

After deployment, invoke Lambda function with multiple inputs, and go to the Step Function Console and view the different invocations to note the different behavior with the different inputs.

To do this, you can run these commands in the terminal (replace `<function-name>` with the value returned in `lambda_function_name`):

```shell
aws lambda invoke --function-name <function-name> --payload '{"key": "value"}' response.json
```
## Output

Upon successful invocation, the function returns the following response -

```json
{
"statusCode": 200,
"body": "{\"message\": \"Successfully connected to the database\", \"database\": \"mydb\", \"host\": \"aurora-serverless-cluster.cluster-cna4c0mg426r.us-east-1.rds.amazonaws.com\"}"
}
```

## Providers

| Name | Version |
|------|---------|
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= "5.84.0" |
65 changes: 65 additions & 0 deletions terraform-lambda-aurora-serverless/example-pattern.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{
"title": "AWS Lambda function to Amazon Aurora Serverless",
"description": "The pattern creates a Lambda function and an Amazon Aurora Cluster with Serverless instance.",
"language": "Python",
"level": "200",
"framework": "Terraform",
"introBox": {
"headline": "How it works",
"text": [
"The pattern creates a Lambda function and an Amazon Aurora Cluster with Serverless instance.",
"It also guides how to invoke the function to access the database."
]
},
"gitHub": {
"template": {
"repoURL": "https://github.com/aws-samples/serverless-patterns/tree/main/terraform-lambda-aurora-serverless",
"templateURL": "serverless-patterns/terraform-lambda-aurora-serverless",
"projectFolder": "terraform-lambda-aurora-serverless",
"templateFile": "terraform-lambda-aurora-serverless/main.tf"
}
},
"resources": {
"bullets": [
{
"test": "Terraform AWS Lambda examples",
"link": "https://github.com/terraform-aws-modules/terraform-aws-lambda/tree/master/examples"
},
{
"test": "Terraform Registry - RDS (Relational Database)",
"link": "https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/rds_cluster.html"
},
{
"text": "Amazon Aurora User Guide",
"link": "https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/CHAP_AuroraOverview.html"
},
{
"test": "AWS Lambda Developer Guide",
"link": "https://docs.aws.amazon.com/lambda/latest/dg/welcome.html"
}
]
},
"deploy": {
"text": [
"terraform init && terraform apply"
]
},
"testing": {
"text": [
"See the GitHub repo for detailed testing instructions."
]
},
"cleanup": {
"text": [
"terraform destroy"
]
},
"authors": [
{
"name": "Saborni Bhattacharya",
"image": "https://drive.google.com/file/d/1AZFquOkafEQRUlrT4hKOtIbt4Cq66SHd/view?usp=sharing",
"bio": "AWS SA, Cloud Enthusiast",
"linkedin": "https://www.linkedin.com/in/saborni-bhattacharya-5b523812a/"
}
]
}
Loading