Develop Functions as a Service (FaaS) more efficiently and productively

Che Kulhan
4 min readSep 28, 2023

--

I was recently working with cloud functions on Amazon’s AWS platform using their Lambda service, and noticed that the cloud IDE was a little clunky and not as user friendly as I am accustomed to, when developing using IDE’s such as VS Code. So I decided to move my development from the the cloud function to my local machine, using the online tool only for deployment.

AWS’s online console for developing Lambda functions

FaaS

Functions-as-a-Service is part of a serverless architecture, available in most cloud platforms such as IBM, Google and Amazon, where the infrastructure behind the code is managed and provisioned by the vendor. These functions offer “on-demand” functionality, as no charges are incurred when the code is not in-use.

FaaS routines are executed in response to events, such as a file upload, user click on a website or when data from an IoT device such as a sensor is inserted into a database. For more information on FaaS, refer to https://martinfowler.com/articles/serverless.html#unpacking-faas.

Cloud Functions on GCP

Within AWS, these functions are called Lambda.

Lambda functions in AWS

Visual Studio Code

As mentioned in the introduction, the code source tool provided with both AWS and Google can be a little clunky to use, so I decided to migrate my development work from the cloud to my local machine, using VS Code, and then “deploy” or copy my working FaaS to the cloud when done. The following example is carried out with AWS and the Python programming language.

Code template for FaaS/Lambda on VS Code

By adding Python’s typical starter code of if __name__==”__main”__: , I am now able to provide a starting point to execute my function locally within VS Code, and I pass through any event data as a dictionary, via the event_data variable. Using a virtual environment, I can simply execute my program within VS Code via the command line:

(venv) >> python3 lambda_function.py

This coincides with the test event that I will create after deploying and testing the code in the AWS cloud.

AWS Test event to invoke the Lambda function

More resources wanted

I then realised that I needed more services, such as S3 and DynamoDB. For further development, I installed AWS’s CLI console, which provides you with programming access to these services.

After installing AWS CLI, create an access key using IAM service, so that the current user is allowed to access AWS resources via AWS CLI.

Once installed, and an access key defined, configure AWS CLI once only, by following the prompts given.

>> aws configure

Using boto3 for Python development, much more functionality can be harnessed locally, before finally copying the code to the AWS Lambda console for deployment. As an example, I can access a DynamoDB table or even an S3 bucket.

VS Code example of using boto3 to access a DynamoDB NoSQL table

Finally, copy directly from VS Code to deploy in the cloud.

Note that in VS Code, I used os.environ as an environment variable to store the table name (TABLE_NAME), while in AWS Lambda this was configured using the Configuration tab on the Lambda function.

Conclusion

I honestly found that is was much more efficient and productive developing FaaS locally using my preferred IDE, Visual Studio Code. Following this methodology, the online GUI within AWS is only used for deployment. Does this make you more efficient and productive?

--

--