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

serverless-haskell

授权协议 MIT License
开发语言 JavaScript
所属分类 云计算、 Serverless 系统
软件类型 开源软件
地区 不详
投 递 者 裴兴言
操作系统 跨平台
开源组织
适用人群 未知
 软件概览

Serverless Haskell

Build statusStackage LTS

Deploying Haskell code onto AWS Lambda using Serverless.

Prerequisites

Usage

There are two ways to start, either via the stack template, or directly modifying a project. You may want to use the manual approach as the template specifies a specific stack resolver as it needs to hardcode the stack.yaml file.

In either case, you will want to have Serverless installed, eg. npm install -g serverless.

Using the stack template

  • Create a Stack package for your code:

    stack new mypackage https://raw.githubusercontent.com/seek-oss/serverless-haskell/master/serverless-haskell.hsfiles
  • Update the resolver in the stack.yaml file. This is hardcoded as the resolver number is not known at template interpolation time. You should pick either the latest resolver, or one you have used before and have thus prebuilt many of the core packages for.

  • Install the dependencies and build the project:

    cd mypackage
    npm install
    stack build
    sls invoke local -f mypackage-func

    This should invoke serverless locally and display output once everything has built.

Manually

  • Create a Stack package for your code:

    stack new mypackage

    LTS 10-17 are supported, older versions are likely to work too but untested.

  • Initialise a Serverless project inside the Stack package directory and installthe serverless-haskell plugin:

    cd mypackage
    npm init -y
    npm install --save serverless serverless-haskell@x.y.z

    The version of the NPM package to install must match the version of theHaskell package.

  • Create serverless.yml with the following contents:

    service: myservice
    
    provider:
      name: aws
      runtime: haskell
    
    functions:
      myfunc:
        handler: mypackage.mypackage-exe
        # Here, mypackage is the Haskell package name and mypackage-exe is the
        # executable name as defined in the Cabal file. The handler field may be
        # prefixed with a path of the form `dir1/.../dirn`, relative to
        # `serverless.yml`, which points to the location where the Haskell
        # package `mypackage` is defined. This prefix is not needed when the
        # Stack project is defined at the same level as `serverless.yml`.
    
    plugins:
      - serverless-haskell
  • Write your main function:

    import qualified Data.Aeson as Aeson
    
    import AWSLambda
    
    main = lambdaMain handler
    
    handler :: Aeson.Value -> IO [Int]
    handler evt = do
      putStrLn "This should go to logs"
      print evt
      pure [1, 2, 3]
  • Add aeson and serverless-haskell to package.yaml:

    dependencies:
    - base >= 4.7 && < 5
    - aeson
    - serverless-haskell
  • Build and test locally using sls invoke local:

    The serverless-haskell plugin will build the package using Stack. Note thatthe first build can take a long time. Consider adding export SLS_DEBUG=* soyou can see what is happening.

    export SLS_DEBUG=*
    sls invoke local -f myfunc
    
  • Use sls deploy to deploy the executable to AWS Lambda.

    The serverless-haskell plugin will build the package using Stack, then uploadit to AWS together with a JavaScript wrapper to pass the input and outputfrom/to AWS Lambda.

    export SLS_DEBUG=*
    sls deploy
    

    You can test the function and see the invocation results with:

    sls invoke -f myfunc`
    

API Gateway

This plugin supports handling API Gateway requests. Declare the HTTP eventsnormally in serverless.yml and useAWSLambda.Events.APIGatewayin the handler to process them.

Serverless Offline can be used for local testing of API Gateway requests. Youmust use --useDocker flag so that the native Haskell runtime works correctly.

When using Serverless Offline, make sure that the project directory isworld-readable, otherwise the started Docker container will be unable to accessthe handlers and all invocations will return HTTP status 502.

Notes

  • Only AWS Lambda is supported at the moment. Other cloud providers wouldrequire different JavaScript wrappers to be implemented.

SeeAWSLambdafor documentation, including additional options to control the deployment.

Development

master branch is the stable version. It is normally released to Hackage oncenew changes are merged via Git tags.

The package is also maintained in Stackage LTS, provided the dependencies arenot blocking it.

Testing

  • Haskell code is tested with Stack: stack test.
  • TypeScript code is linted with eslint.

Integration tests

Integration test verifies that the project can build and deploy a completefunction to AWS, and it runs with expected functionality.

Integration test is only automatically run up to deployment due to the need foran AWS account. To run manually:

  • Ensure you have the required dependencies:
  • Get an AWS account and add the access credentials into your shell environment.
  • Run ./integration-test/run.sh. The exit code indicates success.
  • To verify just the packaging, without deployment, run./integration-test/run.sh --dry-run.
  • By default, the integration test is run with the LTS specified instack.yaml. To specify a different series, use RESOLVER_SERIES=lts-9.
  • To avoid creating a temporary directory for every run, specify--no-clean-dir. This can speed up repeated test runs, but does not guaranteethe same results as a clean test.

Releasing

  • Ensure you are on the master branch.
  • Ensure that all the changes are reflected in the changelog.
  • Run the integration tests.
  • Run ./bumpversion major|minor|patch. This will increment the version number,update the changelog, create and push the Git tag and the branch.
  • If you have released an LTS version, merge the version branch into master,taking care of the conflicts around version numbers and changelog, and releasethe latest version as well.
  • 一.序 1.什么是Haskell?      Haskell是一种函数编程语言. 1980年代以前对函数编程有很多研究, 但不同的研究者使用各自不同的语法记号, 一起交流时造成一些不便. 后来1987年的时候, 在FPCA'87会议上制定了统一的Haskell语言. Haskell吸收了各家的长处, 是一种纯粹的函数编程语言,并根据科学家Haskell B.Curry的名字命名. Haskell经

  • 参考:FaaS(函数即服务) + BaaS(后台即服务)、拉钩教育《玩转 Serverless 架构》课程、Faas,又一个未来? Serverless 说白了,就是一种不用关心服务器的架构思想,开发者可以不关心除业务代码之外的事情,进而提高业务的迭代效率,使用的云服务也是用多少付多少,从而节省成本。总的来讲,Serverless 对开发者研发方式的影响是巨大的。 因为基于 Serverless,

  • haskell在数理逻辑中的应用 基本逻辑运算符定义     逻辑与、逻辑或、蕴涵、相等,逻辑非用not函数,逻辑与用&&函数,逻辑或用||,蕴涵函数定义一个操作符“==>”,然后定义相等操作符“<=>”。 (==>)::Bool->Bool->Bool True==>p =p False==>p =True (<=>)::Bool->Bool->Bool x<=>y=x==y 加载程序后测试一下

  • Serverless即无服务器架构 Serverless是一种理念,主要指一种无服务器架构,这种架构强调开发人员与服务器维护等一系列工作的分离,使用Serverless服务可以使开发人员只关注业务逻辑代码,而不用考虑服务器的操作,比如资源调配、扩容等——这些工作都交由Serverless平台进行处理。 Serverless平台服务 目前Amazon、腾讯、阿里巴巴、百度都对外提供Serverles

  • i定义一个自然数类型 思路: –0是自然数 –if n 是自然数,n+1是自然数 data Nat = Zero | Suc Nat deriving Show —Suc 是后继的意思 nat2Int :: Nat -> Int —Nat类型转换成Int类型 nat2Int Zero = 0 nat2Int (Suc n) = 1 + nat2Int n —这里的n是Nat 类型 —Show Ze

  • haskell默认x:xs中x是首元素,xs是剩余的,若想xs是末尾元素,可以先reverse列表 Not in scrope 没定义 Not instance for …类型错误 对于递归,[1,”asdf”,24] ++ [],结果还是[1,”asdf”,24] 定义变量保存数据,若是局部变量,用where n = ,全局变量则直接在函数底部 n = ,注意不要用出现过的标识符 !!从列表取出

 相关资料
  • 云原生应用开发 回顾过去二十年,应用开发有以下几个显著的特点: 以应用服务器为中心,典型应用服务器包括 tomcat,JBoss,WebLogic,WebSphere,应用服务器提供了丰富的技术堆栈和系统构建范式,对应用开发人员友好 JavaEE/Spring,JavaEE/Spring 是应用开发的基本技能,这项技能有广泛的开发者基础,过去二十年中 JavaEE/Spring 的技术发展/版本的

  • The Serverless Framework (无服务器架构)允许你自动扩展、按执行付费、将事件驱动的功能部署到任何云。 目前支持 AWS Lambda、Apache OpenWhisk、Microsoft Azure,并且正在扩展以支持其他云提供商。 Serverless 降低了维护应用程序的总成本,能够更快地构建更多逻辑。它是一个命令行工具,提供脚手架、工作流自动化和开发部署无服务器架构的最佳实践。它也可以通过插件完全扩展。

  • Serverless Prisma [Archived] — New projects should consider using Prisma2 Minimal Serverless + Prisma Project Template Getting Started Be sure to have Docker and Make installed on your machine. Docker

  • Serverless Webpack A Serverless v1.x & v2.x plugin to build your lambda functions with Webpack. This plugin is for you if you want to use the latest Javascript version with Babel;use custom resource l

  • serverless-bundle serverless-bundle is a Serverless Framework plugin that optimally packages your ES6 or TypeScript Node.js Lambda functions with sensible defaults so you don't have to maintain your o

  • Serverless Express by Vendia Run REST APIs and other web applications using your existing Node.js application framework (Express, Koa, Hapi, Sails, etc.), on top of AWS Lambda and Amazon API Gateway.