DEV Community

PrachiBhende
PrachiBhende

Posted on

Overcoming Docker Installation Woes on Windows Server 2019 for Lambda Function Testing

In the realm of modern software development, testing and deploying applications quickly and efficiently is paramount. However, sometimes the tools we rely on can present unexpected challenges. In this blog post, I'll share my experience grappling with Docker installation issues on Windows Server 2019 and how I found a workaround using serverless-offline to facilitate Lambda function testing.

The Challenge: Docker Installation on Windows Server 2019:

Docker serves as a crucial tool for containerization, offering a streamlined approach to building, shipping, and running applications across different environments. With Docker, we can encapsulate our applications and their dependencies into lightweight, portable containers, ensuring consistency and reliability across development, testing, and production environments.

However, attempts to install Docker on Windows Server 2019 environment, the inability to enable Hyper-V due to compatibility issues posed a major roadblock. Hyper-V is Microsoft's virtualization platform, essential for running Docker on Windows. Without Hyper-V enabled, Docker installation was thwarted, leaving us unable to leverage this powerful tool for containerization.

Enter Serverless-Offline: A Lifesaver in Testing Lambda Functions:

With Docker out of the picture, I began exploring alternative methods to simulate AWS Lambda environments for testing. That's when I stumbled upon serverless-offline, a powerful tool that emulates AWS Lambda and API Gateway on your local machine. Intrigued, I decided to give it a try.

Seamless Setup and Configuration:

Setting up serverless-offline was surprisingly straightforward. With just a few simple commands, I was able to install the necessary dependencies and configure my serverless project to utilize the offline plugin. All you need to do is,

  • Create IAM User for local testing from Amazon Management console and generate access keys under security credentials section. You can download the .csv file that has secret access key and access key ID.

  • Install AWS CLI, click here

  • Configure AWS from command prompt by running the command aws configure, Image description

  • Install NPM packages
    npm install --save-dev serverless-offline serverless-dotenv-plugin
    This will add devDependencies to your package.json

  • Add below lines in the package.json for start command

"scripts": {
    "start-local": "serverless offline start"
  }
Enter fullscreen mode Exit fullscreen mode
  • Create serverless.yml file in the root folder of your application. This is a file for saving all the configurations.
service: project-name
provider:
  name: aws
  runtime: nodejs 20.x
  stage: dev
  region: ap-south-1

plugins:
  - serverless-offline
  - serverless-dotenv-plugin

functions:
  demo-lambda:
    handler: demo-lambda/index.handler
    events:
      - http:
          path:  /demo
          method: ANY
          cors: true
Enter fullscreen mode Exit fullscreen mode
  • Create .env file for storing environment variables. The serverless-dotenv-plugin is for accessing the environment variables.

  • Finally, run the npm run start-local command in the terminal of your VS code. This will list the Links to access the lambda functions. Copy the link and run it from any of the testing applications like postman.

To my delight, I found that it accurately emulated the AWS Lambda environment, allowing me to test my functions locally without the need for Docker or a live AWS environment. This significantly streamlined my development process, enabling rapid iteration and debugging right from my development machine.

Benefits Beyond Docker Dependency:

While serverless-offline proved invaluable in circumventing my Docker woes, its benefits extend beyond mere convenience. By enabling local testing of Lambda functions, it promotes a more efficient and iterative development cycle, empowering developers to iterate quickly and deliver high-quality code with confidence.

Conclusion:

In the face of adversity, it's important to remain adaptable and resourceful. Though Docker installation issues initially threatened to derail my development efforts, serverless-offline emerged as a beacon of hope, providing a viable alternative for testing Lambda functions locally. As developers, we must embrace tools like serverless-offline that empower us to overcome obstacles and continue innovating with confidence.

Stay tuned for my next blog post, where I'll delve into the intricacies of utilizing Secrets Manager and Parameter Store for local testing, further enhancing our development workflow and ensuring secure management of sensitive information. Happy Reading!!

Top comments (0)