For this section we want to create the lambda and connect it to the Microsoft SQL Server we created.
In this step, we will use the Amazon.Lambda.Tools, that we installed in the Create Development Environment step to get the code for our Lambda and API Gatway.
Run the following command to get the lambda code:
git clone https://github.com/StevenDavid/win403-lambda.git
Change the directory to the src code directory:
cd "win403-lambda/src/win403-lambda/"
In the cloud9 file explorer, navigate to the ““win403-lambda/src/win403-lambda/Models/helpers.cs” file and open it.
We need to update lines 24 and 26 of the helpers.cs file with the host address and password for your database. The host endpoint can be found by going to RDS > databases > mssql1 > Connectivity & security tab and coping the endpoint. You need to remember the password you chose when launching the database.
currentCSObject.host = "{host}";
currentCSObject.username = "admin";
currentCSObject.password = "{password}";
Save and close the helpers.cs file.
Open the “win403-lambda/src/win403-lambda/aws-lambda-tools-defaults.json” file and update the s3-bucket with the name of the bucket you created earlier.
Save and close the aws-lambda-tools-defaults.json file.
Open the “win403-lambda/src/win403-lambda/serverless.template” file.
We need to update the SecurityGroupIds with the id of the default security group for your account.
Next we need to updated the SubnetIds. We will use the same subnets that our database is using.
Save and close the serverless.template file.
Congratulations! You now have working code that we need to deploy.