# aws-lambda-dart-runtime **Repository Path**: SimpleZero/aws-lambda-dart-runtime ## Basic Information - **Project Name**: aws-lambda-dart-runtime - **Description**: No description available - **Primary Language**: Unknown - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2020-08-31 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Dart Runtime for AWS Lambda  [](https://www.apache.org/licenses/LICENSE-2.0)
A ๐ฏ Dart Runtime for ฦ AWS Lambda
--- > Read [Introducing a Dart runtime for AWS Lambda](https://aws.amazon.com/de/blogs/opensource/introducing-a-dart-runtime-for-aws-lambda/) > ๐ [Experimental support](#-serverless-framework-experimental) for โก๏ธ serverless framework > If you need to access AWS APIs in your Lambda function, [please search on pub.dev](https://pub.dev/packages?q=dependency%3Ashared_aws_api&sort=popularity) for packages provided by [Agilord](https://www.agilord.com/) ## Features - Great performance `< 10ms` on event processing and `< 50MB` memory consumption - No need to ship the Dart runtime - Multiple event handlers - Typed events - Custom events > this package requires Dart `>= 2.6` > currently `dart2native` only supports building for the platform it is run on, so you must either build on a `Linux` machine or use `docker` ## ๐ Introduction [Dart](https://dart.dev/) is an unsupported [AWS Lambda](https://aws.amazon.com/lambda/) runtime language. However, with a [custom runtime](https://docs.aws.amazon.com/lambda/latest/dg/runtimes-custom.html) you can support virtually every programming language. There are two ways in which you could use [Dart](https://dart.dev/). You could bundle the Dart Runtime in a [Lambda layer](https://docs.aws.amazon.com/lambda/latest/dg/configuration-layers.html) and use JIT compilation within the lambda execution to run a Dart program. The other is to compile a shippable binary of the Dart program. Dart `>= 2.6` introduced `dart2native`. The [tool](https://dart.dev/tools/dart2native) uses AOT (ahead-of-time) to compile a Dart program to [native x64 machine code](https://dart.dev/platforms). This standalone executable is native machine code that's compiled from the specific Dart file and its dependencies, plus a small Dart runtime that handles type checking and garbage collection. We decided to use the latter approach rather then the just-in-time compilation of Dart files. The main reason for this decision is that we wanted to avoid having to ship and maintain a standalone Dart runtime version. We would eventually have to deprecate versions, or always update the version when moving forward. Furthermore, shipping a binary has the advantage of having an always runnable version of your function in addition to performance benefits. We want to highlight [Firecracker open-source innovation](https://www.youtube.com/watch?v=yDplzXEdBTI) from re:Invent 2019 which gives you a brief overview of [Firecracker](https://firecracker-microvm.github.io/) which is the underlying technology of AWS Lambda. ## ๐ฆ Use Add the following snippet to your [pubspec file](https://dart.dev/tools/pub/pubspec) in `pubspec.yaml`. ```yaml dependencies: aws_lambda_dart_runtime: ^1.0.3+2 ``` [Docs](https://awslabs.github.io/aws-lambda-dart-runtime/) are available. They are also accessible in the [`docs`](https://github.com/awslabs/aws-lambda-dart-runtime/blob/docs) folder. ```bash # access the docs local pub global activate dhttpd dhttpd --path docs ``` > you can generate the docs with `dartdoc --output docs` Build and deploy the Dart functions by the [serverless](https://serverless.com) framework or by custom deployment. ### ๐งช Serverless Framework (experimental) Checkout [serverless-dart](https://github.com/katallaxie/serverless-dart) to create your functions with [serverless](https://serverless.com). You can start your next project using the [serverless-aws-dart](https://github.com/katallaxie/serverless-aws-dart) template. ```bash $ npx serverless install \ --url https://github.com/katallaxie/serverless-aws-dart \ --name hello ``` Every [serverless workflow command](https://www.serverless.com/framework/docs/providers/aws/guide/workflow/) should work out of the box. The template also includes an example [GitHub actions](https://github.com/features/actions) [configuration file](.github/workflows/main.yml) which can unlock a virtuous cycle of continuous integration and deployment ( i.e all tests are run on prs and every push to master results in a deployment). ### Custom deployment The deployment is a manual task right now. We have a [`example/build.sh`](https://github.com/awslabs/aws-lambda-dart-runtime/blob/master/example/build.sh) script which makes the process a bit easier. There are three steps to get your code ready to be shipped. 1. Compile your Dart program with `dart2native main.dart -o bootstrap` 2. Create a `.zip` file with `zip lambda.zip bootstrap` 3. Upload the `lambda.zip` to a S3 bucket or use the [AWS CLI](https://aws.amazon.com/cli) to upload it > again, you have to build this on Linux, because `dart2native` does not support cross-compiling When you created your function and upload it via the the console. Please, replace `arn:aws:iam::xxx:xxx` with the role you created for your lambda. ```bash aws lambda create-function --function-name dartTest \ --handler hello.apigateway \ --zip-file fileb://./lambda.zip \ --runtime provided \ --role arn:aws:iam::xxx:xxx \ --environment Variables={DART_BACKTRACE=1} \ --tracing-config Mode=Active ``` Updating a function is a fairly easy task. Rebuild your `lambda.zip` package and execute the following command. ```bash aws lambda update-function-code --function-name dartTest --zip-file fileb://./lambda.zip ``` ## Events There are a number of events that come with the Dart Runtime. - Application Load Balancer - Alexa - API Gateway - AppSync - Cloudwatch - Cognito - DynamoDB - Kinesis - S3 - SQS You can also register custom events. ```dart import 'package:aws_lambda_dart_runtime/aws_lambda_dart_runtime.dart'; class MyCustomEvent { factory MyCustomEvent.fromJson(Map