From fbfc83e73ed8d51393af5f808ec8368f0deb9071 Mon Sep 17 00:00:00 2001 From: Yusuf Mayet Date: Tue, 31 Dec 2024 14:17:05 +0200 Subject: [PATCH 1/4] upgrade to python 3.13 --- lambda-aurora-serverlessv2-postgresql/template.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lambda-aurora-serverlessv2-postgresql/template.yaml b/lambda-aurora-serverlessv2-postgresql/template.yaml index aed423b0d..2012a8fe0 100644 --- a/lambda-aurora-serverlessv2-postgresql/template.yaml +++ b/lambda-aurora-serverlessv2-postgresql/template.yaml @@ -8,7 +8,7 @@ Description: > Globals: Function: CodeUri: ./src - Runtime: python3.12 + Runtime: python3.13 MemorySize: 128 Timeout: 10 LoggingConfig: From 3c0b58e24948436724e6b4eb00bb0b3a002f115a Mon Sep 17 00:00:00 2001 From: Yusuf Mayet Date: Tue, 31 Dec 2024 14:23:55 +0200 Subject: [PATCH 2/4] aurora scale to zero --- lambda-aurora-serverlessv2-postgresql/template.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lambda-aurora-serverlessv2-postgresql/template.yaml b/lambda-aurora-serverlessv2-postgresql/template.yaml index 2012a8fe0..591573db9 100644 --- a/lambda-aurora-serverlessv2-postgresql/template.yaml +++ b/lambda-aurora-serverlessv2-postgresql/template.yaml @@ -65,11 +65,12 @@ Resources: DatabaseName: !Ref DatabaseName Engine: aurora-postgresql EngineMode: provisioned + EngineVersion: '16.4' StorageEncrypted: true # Enable the Data API for Aurora Serverless EnableHttpEndpoint: true ServerlessV2ScalingConfiguration: - MinCapacity: 0.5 + MinCapacity: 0 #auto-pause MaxCapacity: 1 AuroraInstance: Type: 'AWS::RDS::DBInstance' From 0ee9d0b01bc383ce743aad7dcd35309cd16017a6 Mon Sep 17 00:00:00 2001 From: Yusuf Mayet Date: Tue, 31 Dec 2024 14:26:43 +0200 Subject: [PATCH 3/4] set CloudWatch LogGroup --- lambda-aurora-serverlessv2-postgresql/template.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/lambda-aurora-serverlessv2-postgresql/template.yaml b/lambda-aurora-serverlessv2-postgresql/template.yaml index 591573db9..02df867ec 100644 --- a/lambda-aurora-serverlessv2-postgresql/template.yaml +++ b/lambda-aurora-serverlessv2-postgresql/template.yaml @@ -12,6 +12,7 @@ Globals: MemorySize: 128 Timeout: 10 LoggingConfig: + LogGroup: !Sub /aws/lambda/${AWS::StackName} LogFormat: JSON Architectures: - arm64 From aeabfe9b7c19fae9a86889d3b6f5e06f20ca8243 Mon Sep 17 00:00:00 2001 From: Yusuf Mayet Date: Tue, 31 Dec 2024 14:45:25 +0200 Subject: [PATCH 4/4] README updates --- lambda-aurora-serverlessv2-postgresql/README.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lambda-aurora-serverlessv2-postgresql/README.md b/lambda-aurora-serverlessv2-postgresql/README.md index 9cde577ea..5fbcdcfb2 100644 --- a/lambda-aurora-serverlessv2-postgresql/README.md +++ b/lambda-aurora-serverlessv2-postgresql/README.md @@ -39,7 +39,7 @@ Important: this application uses various AWS services and there are costs associ ## How it works -This pattern creates an AWS Lambda function and an [Amazon Aurora PostgreSQL DB](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/Aurora.AuroraPostgreSQL.html) in an [Aurora Serverless v2](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/aurora-serverless-v2.html) DB cluster with [RDS Data API](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/data-api.html) and a Secrets Manager secret. The function creates an example table named "music", inserts a row with data from the event object, then returns the results of a select query. +This pattern creates an AWS Lambda function and an [Amazon Aurora PostgreSQL DB](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/Aurora.AuroraPostgreSQL.html) in an [Aurora Serverless v2](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/aurora-serverless-v2.html) DB cluster that scales to zero, with [RDS Data API](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/data-api.html) and a Secrets Manager secret. The function creates an example table named "music", inserts a row with data from the event object, then returns the results of a select query. ## Testing @@ -67,7 +67,14 @@ Response: } ``` +Aurora Serverless v2 DB instances can automatically pause after a period with no user connections, and automatically resume when a connection request arrives. If it was paused, it will automatically resume and accept the connection. You may see this error in the Lambda logs: +``` +"An error occurred (DatabaseResumingException) when calling the ExecuteStatement operation: The Aurora DB instance arn:aws:rds:..... is resuming after being auto-paused. Please wait a few seconds and try again." +``` + + ## Documentation +- [Amazon Aurora Serverless v2 supports scaling to zero capacity](https://aws.amazon.com/about-aws/whats-new/2024/11/amazon-aurora-serverless-v2-scaling-zero-capacity/) - [Using the Data API for Aurora Serverless](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/data-api.html) - [Data API - ExecuteStatement](https://docs.aws.amazon.com/rdsdataservice/latest/APIReference/API_ExecuteStatement.html) - [Data API - ExecuteStatement Response Elements](https://docs.aws.amazon.com/rdsdataservice/latest/APIReference/API_ExecuteStatement.html#API_ExecuteStatement_ResponseElements)