Skip to content

A template for easily creating and deploying Lambda functions on AWS using TypeScript, compiled with SWC.

License

Notifications You must be signed in to change notification settings

galdoway/typescript-aws-lambda

Repository files navigation

TypeScript Lambda Function Template

This is a TypeScript template for creating AWS Lambda functions, compiled using SWC (Super-fast Web Compiler). With this template, you can quickly set up serverless functions in TypeScript for your AWS Lambda projects.

Features:

🚀 Fast Compilation: SWC compiles TypeScript to JavaScript blazingly fast, ensuring optimal performance for your Lambda functions.

🔧 TypeScript Support: Write your Lambda functions using TypeScript, with full type safety and modern language features.

📦 Ready-to-Use: Start building your Lambda functions right away with a pre-configured project structure.

🧪 Testing Friendly: Easily integrate testing frameworks like Jest or Mocha for unit and integration testing of your Lambda functions.

📚 Documentation: Includes a README with clear instructions on getting started, configuration, and usage.

Getting Started

To get started with this template, follow these steps:

  • Clone the Repository: Clone this repository to your local machine using git clone https://github.com/your-repo/template.git.
  • Install Dependencies: Run npm install to install all required dependencies.
  • Write Your Function: Implement your Lambda function logic in the src/index.ts file.
  • Build: Run npm run build to compile your TypeScript code to JavaScript using SWC.
  • Deploy: Deploy your Lambda function to AWS using your preferred method (e.g., AWS CLI, Serverless Framework, AWS CDK).

Configuration

This template comes pre-configured with the following settings:

AWS SDK: The AWS SDK is included by default, allowing you to interact with AWS services within your Lambda function. Environment Variables: You can define environment variables in the serverless.yml file for configuration. Usage To use this Lambda function template, follow these guidelines:

Function Logic: Implement your Lambda function logic in the src/index.ts file. Input/Output: Define the input/output structure of your function based on your requirements. Testing: Write unit tests using your preferred testing framework (e.g., Jest, Mocha). Deployment: Deploy your Lambda function to AWS Lambda using your preferred deployment method. Example typescript Copy code

import { APIGatewayProxyHandler } from 'aws-lambda';

export const handler: APIGatewayProxyHandler = async (event) => {
  try {
    // Your Lambda function logic here
    const response = {
      statusCode: 200,
      body: JSON.stringify({
        message: 'Hello from Lambda!',
        input: event,
      }),
    };
    return response;
  } catch (error) {
    console.error('Error:', error);
    return {
      statusCode: 500,
      body: JSON.stringify({
        message: 'Internal Server Error',
      }),
    };
  }
};

License

This project is licensed under the MIT License - see the LICENSE file for details.


Feel free to customize this template to fit your specific requirements. Happy coding! 🎉

About

A template for easily creating and deploying Lambda functions on AWS using TypeScript, compiled with SWC.

Topics

Resources

License

Stars

Watchers

Forks