myConsciousness / aws-lambda-dart-runtime-ns

A powerful runtime to build Lambda functions in Dart with native AWS events. Sound null safety.
https://pub.dev/packages/aws_lambda_dart_runtime_ns
Apache License 2.0
3 stars 3 forks source link
aws aws-lambda aws-lambda-dart aws-lambda-runtime

Dart Runtime for AWS Lambda (Sound Null Safety)

A 🎯 Dart Runtime for ƛ AWS Lambda


This package is based on the official aws-lambda-dart-runtime. It is a restructured version of the outdated official aws-lambda-dart-runtime adapted to the latest Dart SDK to make it easier to maintain.

Thanks to katallaxie and AWS Labs involved in the development of the original stuff!

You can read the official document too!


Features

Read Introducing a Dart runtime for AWS Lambda

📦 Install

You can easily add this package to your app.

dart pub add aws_lambda_dart_runtime_ns
dart pub get

ƛ Use

import 'package:aws_lambda_dart_runtime_ns/aws_lambda_dart_runtime_ns.dart';

Future<void> main() async => await invokeAwsLambdaRuntime([
      _sayHelloWorldFunction,
      _doSomethingFunction,
      _sayHelloWorldForApiGatewayFunction,
    ]);

/// GET endpoint that just returns "Hello, World!".
FunctionHandler get _sayHelloWorldFunction => FunctionHandler(
      name: 'main.helloWorld',
      action: (context, event) {
        return InvocationResult(
          requestId: context.requestId,
          body: {
            'message': 'Hello, World!',
          },
        );
      },
    );

/// POST endpoint does something.
FunctionHandler get _doSomethingFunction => FunctionHandler(
      name: 'main.doSomething',
      action: (context, event) {
        // Do something here...

        return InvocationResult(requestId: context.requestId);
      },
    );

/// GET endpoint that returns "Hello, World!" with statusCode and headers.
FunctionHandler get _sayHelloWorldForApiGatewayFunction => FunctionHandler(
      name: 'main.helloWorld',
      action: (context, event) {
        return InvocationResult(
          requestId: context.requestId,
          body: AwsApiGatewayResponse.fromJson(
            {'message': 'Hello, World!'},
            isBase64Encoded: false,
            statusCode: 200,
            headers: const {'Content-Type': 'application/json'},
          ),
        );
      },
    );

License

Apache 2.0

We :blue_heart: Dart.