当前位置: 首页 > 软件库 > 云计算 > >

hal

授权协议 View license
开发语言 Haskell
所属分类 云计算
软件类型 开源软件
地区 不详
投 递 者 骆磊
操作系统 跨平台
开源组织
适用人群 未知
 软件概览

hal

A runtime environment for Haskell applications running on AWS Lambda.

Flexible

This library uniquely supports different types of AWS Lambda Handlers for your needs/comfort with advanced Haskell.Instead of exposing a single function that constructs a Lambda, this library exposes many.

For lambdas that are pure and safe, then pureRuntime is ideal.It accepts a handler with the signature (FromJSON a, ToJSON b) => a -> b.This runtime guarantees that side-effects cannot occur.

For advanced use cases mRuntime unlocks the full power of Monad Transformers.It accepts handlers with the signature (MonadCatch m, MonadIO m, FromJSON event, ToJSON result) => (event -> m result)This enables users to add caching logic or expose complex environments.

With numerous options in between these two, developers can choose the right balance of flexibility vs simplicity.

Performant

Measuring lambda performance is tricky, so investigation and optimization is ongoing.Current indications show a warm execution overhead of only ~20% more than the official Rust Runtime (a much lower level language).

Robust

While testing continues, we have executed over 30k test events without error caused by the runtime.Naive approaches lead to error rates well over 10%.

Table of Contents

Supported Platforms / GHC Versions

We currently support this library under the same environment that AWS Lambdasupports.

Our CI currently targets the latest three LTS Stackage Versions,the latest three minor versions of GHC under Cabal(e.g. 8.6.x, 8.4.x, and 8.2.x), and GHC-head / Stackage nightly builds.

If you haven't already, adding docker: { enable: true } to your stack.yamlfile will ensure that you're building a binary that can run inAWS Lambda.

Quick Start

This quick start assumes you have the following tools installed:

Add hal to your stack.yaml's extra-deps and enableDocker integration so that your binary is automatically compiled in acompatible environment for AWS. Also add hal to your project'sdependency list (either project-name.cabal or package.yaml)

#...
packages:
  - '.'
  - hal-0.1.2
# ...
docker:
  enable: true
# ...

Then, define your types and handler:

{-# LANGUAGE DeriveGeneric  #-}
{-# LANGUAGE NamedFieldPuns #-}

module Main where

import AWS.Lambda.Runtime (pureRuntime)
import Data.Aeson         (FromJSON, ToJSON)
import GHC.Generics       (Generic)

data IdEvent  = IdEvent { input   :: String } deriving Generic
instance FromJSON IdEvent

data IdResult = IdResult { output :: String } deriving Generic
instance ToJSON IdResult

handler :: IdEvent -> IdResult
handler IdEvent { input } = IdResult { output = input }

main :: IO ()
main = pureRuntime handler

Your binary should be called bootstrap in order for the custom runtimeto execute properly:

# Example snippet of package.yaml
# ...
executables:
  bootstrap:
    source-dirs: src
    main: Main.hs  # e.g. {project root}/src/Main.hs
# ...

You'll need to either build on a compatible linux host or inside a compatible docker container (or some other mechanism like nix).Note that current Stack LTS images are not compatible.If you see an error message that contains "version 'GLIBC_X.XX' not found" when running (hosted or locally), then your build environment is not compatible.

Enable stack's docker integration and define an optional image within stack.yaml:

# file: stack.yaml
docker:
  enabled: true
  # If omitted, this defaults to fpco/stack-build:lts-${YOUR_LTS_VERSION}
  image: ${BUILD_IMAGE}

Don't forget to define your CloudFormation stack:

# file: template.yaml
AWSTemplateFormatVersion: '2010-09-09'
Transform: 'AWS::Serverless-2016-10-31'
Description: Test for the Haskell Runtime.
Resources:
  HelloWorldApp:
    Type: 'AWS::Serverless::Function'
    Properties:
      Handler: NOT_USED
      Runtime: provided
      # CodeUri is a relative path from the directory that this CloudFormation
      # file is defined.
      CodeUri: .stack-work/docker/_home/.local/bin/
      Description: My Haskell runtime.
      MemorySize: 128
      Timeout: 3

Finally, build, upload and test your lambda!

# Build the binary, make sure your executable is named `bootstrap`
stack build --copy-bins

# Create your function package
aws cloudformation package \
  --template-file template.yaml
  --s3-bucket your-existing-bucket > \
  deployment_stack.yaml

# Deploy your function
aws cloudformation deploy \
  --stack-name "hello-world-haskell" \
  --region us-west-2 \
  --capabilities CAPABILITY_IAM \
  --template-file deployment_stack.yaml

# Take it for a spin!
aws lambda invoke \
  --function-name your-function-name \
  --region us-west-2
  --payload '{"input": "foo"}'
  output.txt

Local Testing

Dependencies

Build

docker pull fpco/stack-build:lts-{version} # First build only, find the latest version in stack.yaml
stack build --copy-bins

Execute w/ Docker

echo '{ "accountId": "byebye" }' | docker run -i --rm \
    -e DOCKER_LAMBDA_USE_STDIN=1 \
    -v ${PWD}/.stack-work/docker/_home/.local/bin/:/var/task \
    lambci/lambda:provided

Execute w/ SAM Local

Note that hal currently only supports aws-sam-cli on versions <1.0.

echo '{ "accountId": "byebye" }' | sam local invoke --region us-east-1
 相关资料
  • 问题内容: 我将以下代码与具有Half_even舍入模式的Java BigDecimal setScale方法配合使用,并获得以下结果。 结果:1.11 预期值:1.12 由于最接近5的偶数应该是2,因此我期望的结果是1.12。但是结果是1.11。然后再次, 结果:1.15 预期值:1.14 因为5左边的偶数是4,所以我期望结果是1.14。有什么解释吗? 问题答案: 这是由浮点不精确(在您的输入值

  • 本文向大家介绍Hallo.js基于jQuery UI所见即所得的Web编辑器,包括了Hallo.js基于jQuery UI所见即所得的Web编辑器的使用技巧和注意事项,需要的朋友参考一下 先看看效果: Hallo.js是一个简单的富文本Web编辑器,基于jQuery UI并且利用HTML5的contentEditable实现所见即所得。其目标并不是取代当今非常流行的编辑器,如 TinyMCE 或

  • 问题内容: 根据 HAL标准 (请参阅此处和此处),与其他资源的链接应放在特定的嵌入式部分中。 因此,例如这不是有效的HAL,我的理解正确吗? 上述JSON无效的原因是,链接应放在链接到主体ID 的嵌入部分( “ _embedded” )中。因此正确的方法是: 以上所有正确吗? 谢谢 问题答案: 将用它作为用hal重新设计的案例研究。@darrel millers的回答是好的,但不是很好,我认为有

  • 本文向大家介绍Ubuntu中为Android简单介绍硬件抽象层(HAL),包括了Ubuntu中为Android简单介绍硬件抽象层(HAL)的使用技巧和注意事项,需要的朋友参考一下           Android的硬件抽象层,简单来说,就是对Linux内核驱动程序的封装,向上提供接口,屏蔽低层的实现细节。           对硬件的支持分成了两层,一层放在用户空间(User Space),一层

  • 问题内容: 在2.0.2.RELEASE中将Spring Data REST与JPA结合使用。 如何禁用JSON中的超文本应用语言(HAL)?http://stateless.co/hal_specification.html 我已经尝试了很多东西,但无济于事。例如,我已经将Accept和Content-type标头设置为“ application / json”而不是“ application

  • 嗨,我是Spring Boot子的新手。Spring防尘套启动器执行器在以下情况下工作正常http://localhost:8080/actuator. 我的Spring引导版本是2.2.4 on添加 应用程序启动失败。 还有我的pom。xml是 帮我解决这个问题。 非常感谢。

  • 我是Coda Hale Metrics的新手。我创建了一个示例spring应用程序,它有一个简单的RESTful web服务方法。 我使用了Coda Hale Metrics framework提供的Meter、Timer和Counter工具来跟踪请求数量、请求比率和请求持续时间。目前,我使用console Reporter of Metrics(请查找下面的代码)将这些信息输出到控制台。 我有几

  • 留档说 用户可以通过在度量名称前加上适当的类型(例如直方图、米)来创建Coda Hale度量。 我认为这意味着我可以使用一个计数器或带有“meter.*”形式的度量名称的量规,这将作为一个度量。我试过了 但是,当我访问“管理/指标”时,我看到的只是计数,而不是计量的比率。在Spring靴中使用尾波黑尔计的正确方法是什么。文档中不太清楚集成是如何工作的。