


The format and content for the test event are not relevant for this exercise, so pick any Event template, such as Hello World, input a memorable Event name, such as MyTestEvent and click Create. You will be asked to configure a test event the first time you try.

Nodejs api aws postgresql code#
Switch back to the Code tab, and click the Test button in the Code source section. This is accomplished in a minimal number of lines of code. The function doesn't bundle a database driver, it simply uses a RESTful AWS API call to send the SQL query: SHOW TABLES and retrieves the result as a JSON data structure. Now you are ready to connect to the database from a Lambda function, by using the RDS Data API.

Connect to the database using the RDS Data API ¶ The compute capacity will be allocated only when the first request is received.ģ. We are increasing the timeout as it will take longer to respond to the first query against the serverless DB cluster. Choose General configuration from the left side menu, and click the Edit button.Ĭhange the function Timeout to 1 min 0 sec, then click Save. Create a secret to store the credentials.Ĭonst rdsDataService = new AWS.RDSDataService()Įxports.handler = (event, context, callback) => Ĭonsole.log('Found rows: ' + rows.length) See the previous lab: Create an Aurora Serverless DB Cluster at step 2. RDS Data API will access this secret and connect to the database using those credentials. The ARN of the secret used to store the database credentials. See the previous lab: Create an Aurora Serverless DB Cluster at step 1. RDS Data API will establish connectivity with this database on your behalf. The ARN of the serverless database cluster resource. In the Code source section, paste the code snipped below into the editor, and change the placeholders as follows: Placeholder In the Execution role dropdown, select Use an existing role, then in the Existing role dropdown, select the execution role you have created previously, named auroralab-serverless-role. Under Permissions, expand the sub-section called Choose or create an execution role. Then assign the role the name auroralab-serverless-role, and click Create role.Ĭhoose Functions from the left hand side menu, if it isn't already selected, and click Create function.Ĭhoose the option to Author from scratch, set the Function name to auroralab-serverless-function and select Node.js 14.x for Runtime. Skip the Add tags section, and click Next: Review. Select that policy, and click Next: tags. You can also close the policy browser tab.īack on the browser tab for creating the role, click the refresh icon in the top right of the policy list, then use the filter input field to search for the name of the policy you have just created. Once the policy has been created successfully, you can return to the other browser tab and continue configuring the role. Assign the IAM policy the name auroralab-serverless-policy, then click Create policy. On the Add tags (Optional) screen, click Next: Review. Connect to the database using the RDS Data APIĬreate an Aurora Serverless v2 DB Cluster Use Aurora Serverless with AWS Lambda Functionsģ. Recover from an Unplanned Primary DB Cluster FailureĬreate an Aurora Serverless v1 DB Cluster Observe and Identify SQL Performance Issues
