Skip to content

v2 - Removal of layer #30

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jun 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 0 additions & 35 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@ jobs:
- stack-{{checksum "stack.yaml"}}-{{checksum "package.yaml"}}
- run: stack setup
- run: stack build
- run: cd $(stack path --local-install-root)/bin/ && zip -j /tmp/runtime.zip bootstrap
- save-cache:
key: zip-file
paths:
- "/tmp/runtime.zip"
- save-cache:
key: stack-{{ checksum "stack.yaml" }}
paths:
Expand Down Expand Up @@ -63,42 +58,12 @@ jobs:
- store_test_results:
path: ~/.stack-work/logs/*

deploy:
docker:
- image: circleci/python:2.7-jessie
working_directory: ~/aws-lambda-haskell-runtime
steps:
- checkout
- restore-cache:
key: zip-file
paths:
- "/tmp/"
- run:
name: Install awscli
command: sudo pip install awscli
- run:
name: Deploy to AWS Layers
command: |
LAYER_NAME="aws-haskell-runtime"
REGIONS_LIST="us-east-1 us-east-2 us-west-1 us-west-2 ap-south-1 ap-northeast-2 ap-southeast-1 ap-southeast-2 ap-northeast-1 ca-central-1 eu-central-1 eu-west-1 eu-west-2 eu-west-3 eu-north-1 sa-east-1"
for region in $REGIONS_LIST
do
aws lambda publish-layer-version --layer-name $LAYER_NAME --zip-file fileb:///tmp/runtime.zip --region $region
aws lambda add-layer-version-permission --layer-name $LAYER_NAME --version-number $(aws lambda list-layer-versions --layer-name $LAYER_NAME --region $region | grep Version | tail -n+3 | head -n 1 | cut -d: -f2- | rev | cut -d, -f2 | rev) --principal '*' --action lambda:GetLayerVersion --statement-id allow-getLayerVersion-all --region $region
done

workflows:
version: 2
build-and-deploy:
jobs:
- build
- test
- deploy:
requires:
- build
filters:
branches:
only: master

general:
branches:
Expand Down
3 changes: 0 additions & 3 deletions ChangeLog.md

This file was deleted.

2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright 2018 The Agile Monkeys
Copyright 2019 The Agile Monkeys

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
11 changes: 0 additions & 11 deletions Makefile

This file was deleted.

13 changes: 2 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ This package provides a way of running Haskell projects on AWS Lambda.
## Sample lambda function

```
stack new my-haskell-lambda https://github.com/theam/aws-lambda-haskell-runtime/raw/master/stack-template.hsfiles --resolver=lts-13.0 --omit-packages
stack new my-haskell-lambda https://github.com/theam/aws-lambda-haskell-runtime/raw/master/stack-template.hsfiles --resolver=lts-13.25 --omit-packages
cd my-haskell-lambda
stack docker pull
```
Expand All @@ -21,7 +21,7 @@ packages:
- .

extra-deps:
- aws-lambda-haskell-runtime-1.0.10
- aws-lambda-haskell-runtime-2.0.0
```

to your `stack.yaml`
Expand All @@ -34,15 +34,6 @@ make

Now you should have a `build/function.zip` file that you can upload to your lambda.

## Lambda function configuration

When creating your lambda function you need to provide a layer with the Haskell runtime. We have deployed the layer to our AWS account, you can use it or deploy it to your own AWS account.

The ARN of the runtime layer is:
```
arn:aws:lambda:<YOUR REGION>:785355572843:layer:aws-haskell-runtime:5
````

## Full user guide

Take a look at the [Getting Started with the Haskell AWS Lambda Runtime](https://medium.com/the-theam-journey/getting-started-with-the-haskell-aws-lambda-runtime-951b2322c7a3) guide.
21 changes: 0 additions & 21 deletions app/Main.hs

This file was deleted.

13 changes: 1 addition & 12 deletions package.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: aws-lambda-haskell-runtime
version: 1.1.1
version: 2.0.0
github: "theam/aws-lambda-haskell-runtime"
license: Apache-2.0
author: Nikita Tchayka
Expand All @@ -23,11 +23,8 @@ library:
- bytestring
- http-client
- http-types
- optparse-generic
- process
- template-haskell
- text
- uuid
- safe-exceptions-checked
- path
- path-io
Expand All @@ -36,14 +33,6 @@ library:
- Aws.Lambda
- Aws.Lambda.Runtime

executables:
bootstrap:
source-dirs: app
main: Main.hs
dependencies:
- aws-lambda-haskell-runtime
- http-client

tests:
aws-lambda-haskell-runtime-test:
main: Spec.hs
Expand Down
1 change: 1 addition & 0 deletions src/Aws/Lambda.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ module Aws.Lambda
) where

import Aws.Lambda.Configuration as Reexported
import Aws.Lambda.Runtime as Reexported
import Aws.Lambda.Runtime.Context as Reexported
15 changes: 5 additions & 10 deletions src/Aws/Lambda/Configuration.hs
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
{-# OPTIONS_GHC -fno-warn-unused-pattern-binds #-}
module Aws.Lambda.Configuration
( Main.LambdaOptions(..)
, Main.generate
, Main.getRecord
, configureLambda
, IPC.returnAndFail
, IPC.returnAndSucceed
, generateLambdaDispatcher
, Dispatch.decodeObj
, Dispatch.encodeObj
)
where

Expand All @@ -15,13 +12,11 @@ import qualified Language.Haskell.TH as Meta
import qualified Aws.Lambda.Meta.Dispatch as Dispatch
import qualified Aws.Lambda.Meta.Main as Main
import qualified Aws.Lambda.Meta.Run as Run
import qualified Aws.Lambda.Runtime.IPC as IPC

{-| Generates a @main@ function to be used with the
AWS Lambda layer.
{-| Generates a @main@ function that acts as a dispatcher
-}
configureLambda :: Meta.DecsQ
configureLambda = do
generateLambdaDispatcher :: Meta.DecsQ
generateLambdaDispatcher = do
main <- Main.generate
run <- Run.generate
return (main <> [run])
5 changes: 5 additions & 0 deletions src/Aws/Lambda/Meta/Common.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module Aws.Lambda.Meta.Common
( declarationName
, expressionName
, getFieldsFrom
, constructorName
) where

import Data.Text (Text)
Expand All @@ -19,6 +20,10 @@ declarationName = pure . VarP . mkName . Text.unpack
expressionName :: Text -> Q Exp
expressionName = pure . VarE . mkName . Text.unpack

-- | Helper for defining names for constructors
-- think of @Foo@ in @quux = Foo 3@
constructorName :: Text -> Q Exp
constructorName = pure . ConE . mkName . Text.unpack

-- | Helper for extracting fields of a specified record
-- it expects the constructor name as the first parameter,
Expand Down
15 changes: 13 additions & 2 deletions src/Aws/Lambda/Meta/Dispatch.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
module Aws.Lambda.Meta.Dispatch
( generate
, decodeObj
, encodeObj
, Runtime.LambdaResult(..)
) where

import Data.Function ((&))
Expand All @@ -13,6 +15,7 @@ import qualified Data.ByteString.Lazy.Char8 as LazyByteString
import qualified Language.Haskell.TH as Meta

import Aws.Lambda.Meta.Common
import qualified Aws.Lambda.Runtime.Common as Runtime

{-| Helper function that the dispatcher will use to
decode the JSON that comes as an AWS Lambda event into the
Expand All @@ -24,6 +27,14 @@ decodeObj x =
Left e -> error e
Right v -> v

{-| Helper function that the dispatcher will use to
decode the JSON that comes as an AWS Lambda event into the
appropriate type expected by the handler.
-}
encodeObj :: ToJSON a => a -> String
encodeObj x = LazyByteString.unpack (encode x)


{-| Generates the dispatcher out of a list of
handler names in the form @src/Foo/Bar.handler@

Expand All @@ -43,7 +54,7 @@ handlerCase lambdaHandler = do
let pat = Meta.LitP (Meta.StringL $ Text.unpack lambdaHandler)
body <- [e|do
result <- $(expressionName qualifiedName) (decodeObj $(expressionName "eventObject")) (decodeObj $(expressionName "contextObject"))
either (returnAndFail $(expressionName "executionUuid")) (returnAndSucceed $(expressionName "executionUuid")) result |]
either (pure . Left . encodeObj) (pure . Right . $(constructorName "LambdaResult") . encodeObj) result |]
pure $ Meta.Match pat (Meta.NormalB body) []
where
qualifiedName =
Expand All @@ -56,6 +67,6 @@ unmatchedCase :: Meta.MatchQ
unmatchedCase = do
let pattern = Meta.WildP
body <- [e|
returnAndFail $(expressionName "executionUuid") ("Handler " <> $(expressionName "functionHandler") <> " does not exist on project")
pure $ Left ("Handler " <> $(expressionName "functionHandler") <> " does not exist on project")
|]
pure $ Meta.Match pattern (Meta.NormalB body) []
24 changes: 9 additions & 15 deletions src/Aws/Lambda/Meta/Main.hs
Original file line number Diff line number Diff line change
@@ -1,27 +1,21 @@
{-| main function generation for interoperation with the layer -}
module Aws.Lambda.Meta.Main
( LambdaOptions(..)
( Runtime.LambdaOptions(..)
, generate
, Options.getRecord
) where

import GHC.Generics (Generic)

import qualified Language.Haskell.TH as Meta
import qualified Options.Generic as Options

import Aws.Lambda.Meta.Common
import qualified Aws.Lambda.Runtime.Common as Runtime

-- | Options that the generated main expects
data LambdaOptions = LambdaOptions
{ eventObject :: !String
, contextObject :: !String
, functionHandler :: !String
, executionUuid :: !String
} deriving (Generic, Options.ParseRecord)

-- | Generate the main function that the layer will call
-- | Generate the main function with the dispatcher
generate :: Meta.DecsQ
generate = [d|
$(declarationName "main") = getRecord "" >>= run
$(declarationName "main") = $(directCallBody)
|]
where
directCallBody =
[e|do
runLambda run
|]
6 changes: 0 additions & 6 deletions src/Aws/Lambda/Meta/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@ import Aws.Lambda.Meta.Common
import qualified Aws.Lambda.Meta.Discover as Discover
import qualified Aws.Lambda.Meta.Dispatch as Dispatch

{-| Generate the run function

It will create a dispatcher that is a huge @case@ expression that
expects the name of the handler provided by AWS Lambda, and will
execute the appropriate user function
-}
generate :: Meta.DecQ
generate = do
handlers <- Meta.runIO Discover.handlers
Expand Down
Loading