Skip to content

Commit 2ea7417

Browse files
committed
2 parents c004aac + 1b2f443 commit 2ea7417

File tree

10 files changed

+710
-0
lines changed

10 files changed

+710
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
builds/*
2+
.terraform
3+
.terraform.*
4+
function.zip
5+
src/function/pymysql
6+
src/function/pymysql/*
7+
src/function/PyMySQL-1.1.0.dist-info
8+
src/function/PyMySQL-1.1.0.dist-info/*
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# AWS Lambda function to Amazon Aurora Serverless
2+
3+
The pattern creates an AWS Lambda function and an Amazon Aurora Serverless cluster, a Log group and the IAM resources required to run the application. The database credentials are stored in AWS Secrets Manager secret.
4+
5+
The Lambda function is written in Python that uses pymysql client to establish connectivity with the serverless database.
6+
7+
## Getting started with Terraform Serverless Patterns
8+
9+
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).
10+
11+
## Steps
12+
13+
First of all, you will need to install the 'pymysql' client depedency which is used in the Lambda function code.
14+
```shell
15+
cd src/function
16+
pip3 install -r requirements.txt -t .
17+
cd ../..
18+
```
19+
Then perform the following terraform commands to deploy the stack
20+
```shell
21+
terraform init
22+
terrform apply
23+
```
24+
25+
Naming constraints with Amazon Aurora for Master password:
26+
- The password for the database master user can include any printable ASCII character except /, ', ", @, or a space.
27+
- The password can contain the following number of printable ASCII characters depending on the DB engine: Aurora MySQL: 8–41 and Aurora PostgreSQL: 8–99.
28+
For more information, please refer to [this](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/CHAP_Limits.html#RDS_Limits.Constraints)
29+
30+
31+
32+
## Testing
33+
34+
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.
35+
36+
To do this, you can run these commands in the terminal (replace `<function-name>` with the value returned in `lambda_function_name`):
37+
38+
```shell
39+
aws lambda invoke --function-name <function-name> --payload '{"key": "value"}' response.json
40+
```
41+
## Output
42+
43+
Upon successful invocation, the function returns the following response -
44+
45+
```json
46+
{
47+
"statusCode": 200,
48+
"body": "{\"message\": \"Successfully connected to the database\", \"database\": \"mydb\", \"host\": \"aurora-serverless-cluster.cluster-cna4c0mg426r.us-east-1.rds.amazonaws.com\"}"
49+
}
50+
```
51+
52+
## Providers
53+
54+
| Name | Version |
55+
|------|---------|
56+
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= "5.84.0" |
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
{
2+
"title": "AWS Lambda function to Amazon Aurora Serverless",
3+
"description": "The pattern creates a Lambda function and an Amazon Aurora Cluster with Serverless instance. The Database credentials are stored and accessed from AWS Secrets Manager.",
4+
"language": "Python",
5+
"level": "300",
6+
"framework": "Terraform",
7+
"introBox": {
8+
"headline": "How it works",
9+
"text": [
10+
"The pattern creates a Lambda function and an Amazon Aurora Cluster with Serverless instance.",
11+
"The Database credentials are stored and accessed from AWS Secrets Manager.",
12+
"It also guides how to invoke the function to access the database."
13+
]
14+
},
15+
"gitHub": {
16+
"template": {
17+
"repoURL": "https://github.com/aws-samples/serverless-patterns/tree/main/terraform-lambda-aurora-serverless",
18+
"templateURL": "serverless-patterns/terraform-lambda-aurora-serverless",
19+
"projectFolder": "terraform-lambda-aurora-serverless",
20+
"templateFile": "terraform-lambda-aurora-serverless/main.tf"
21+
}
22+
},
23+
"resources": {
24+
"bullets": [
25+
{
26+
"test": "Terraform AWS Lambda examples",
27+
"link": "https://github.com/terraform-aws-modules/terraform-aws-lambda/tree/master/examples"
28+
},
29+
{
30+
"test": "Terraform Registry - RDS (Relational Database)",
31+
"link": "https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/rds_cluster.html"
32+
},
33+
{
34+
"text": "Amazon Aurora User Guide",
35+
"link": "https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/CHAP_AuroraOverview.html"
36+
},
37+
{
38+
"test": "AWS Lambda Developer Guide",
39+
"link": "https://docs.aws.amazon.com/lambda/latest/dg/welcome.html"
40+
}
41+
]
42+
},
43+
"deploy": {
44+
"text": [
45+
"terraform init && terraform apply"
46+
]
47+
},
48+
"testing": {
49+
"text": [
50+
"See the GitHub repo for detailed testing instructions."
51+
]
52+
},
53+
"cleanup": {
54+
"text": [
55+
"terraform destroy"
56+
]
57+
},
58+
"authors": [
59+
{
60+
"name": "Saborni Bhattacharya",
61+
"image": "https://drive.google.com/file/d/1AZFquOkafEQRUlrT4hKOtIbt4Cq66SHd/view?usp=sharing",
62+
"bio": "AWS SA, Cloud Enthusiast",
63+
"linkedin": "https://www.linkedin.com/in/saborni-bhattacharya-5b523812a/"
64+
}
65+
]
66+
}

0 commit comments

Comments
 (0)