How to Configure — write — deploy AWS Server less Lambda functions.
In This article I would go in detail how I was able to setup, write and deploy lambda functions to AWS.
Initial Setup Required for your local Environment set up.
First You need to have AWS account, you can create one by signing in to https://console.aws.amazon.com/
Now as you might be a root user, you need to create a user in IAM , as development should not be done using root user account. So if you already have a user check if he has IAM permissions to run/deploy lambda, I provided full access to user account but that is not suggested.
As shown in the Image if you have a user you can click on create access key to get access key related details which we need to configure in Environment variables of developer machine.
You need to have the first 3 settings added in your system environment variables, we can get them from the AWS console as shown in my Figure 2.
Now We need to Install AWS CLI in our local machine. Follow this URL
We Also need Node.js and Docker installed for this setup.
Here is the MSI for Windows users :
Once you install AWS MSI.
After installation, Goto command promt and type “AWS HELP” to check whether aws cli is installed or not.
As we already configured all the environment variables as shown in Figure 2, 3. We should be able to use command “aws sts get-caller-identity” to get user setup in our local machine.
This Figure 5 indicates good sign that our local setup is ready for aws operations like moving files to S3, deploying lambda functions…etc..
Now In VS Code I created a folder called API and added index.js file which is my lambda function.
Before deploying this lambda we need to create s3 bucket for storing our lambda folder which needs to be deployed.
To copy our lambda to s3 use the below command
aws s3 cp ZipFileLocation s3://bucketname
eg:
“aws s3 cp api/api.zip s3://praveentestabc”
To deploy the function copied in S3 use below command
aws lambda update-function-code — function-name LambdaName — s3-bucket bucketname— s3-key fileName — publish
eg:
aws lambda update-function-code — function-name TestSum — s3-bucket praveentestabc — s3-key api.zip — publish
Once deployed we can go to aws lambda to see the deployed version and test it via API gate way or click on test button
Hope this gives you detailed explanation on How to Setup/Write/Deploy AWS lambda functions.