# serverless-groovy

> Serverless Framework Plugin for Groovy

Latest version **0.0.4** (published 2019-12-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install serverless-groovy
pnpm add serverless-groovy
yarn add serverless-groovy
bun add serverless-groovy
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.4 |
| Published | 2019-12-07 |
| First published | 2019-11-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 13 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Rowell Belen |
| Maintainers | bytekast |
| Keywords | serverless, serverless, framework, groovy, java, lambda, aws, amazon, web, services, faas |

## Links

- npm: https://www.npmjs.com/package/serverless-groovy
- Repository: https://github.com/bytekast/serverless-toolkit
- Homepage: https://github.com/bytekast/serverless-toolkit/plugins/serverless-groovy-plugin#readme
- Issues: https://github.com/bytekast/serverless-toolkit/issues
- npm.io page: https://npm.io/package/serverless-groovy

## Alternatives

- [@opentelemetry/exporter-zipkin](https://npm.io/package/@opentelemetry/exporter-zipkin.md) — 14.8M weekly downloads
- [pusher-js](https://npm.io/package/pusher-js.md) — 2.0M weekly downloads
- [browserify](https://npm.io/package/browserify.md) — 1.7M weekly downloads
- [sqs-consumer](https://npm.io/package/sqs-consumer.md) — 1.7M weekly downloads
- [@sanity/eventsource](https://npm.io/package/@sanity/eventsource.md) — 930.8K weekly downloads

## Recent versions

- 0.0.4 (latest) — 2019-12-07
- 0.0.3 — 2019-11-17
- 0.0.2 — 2019-11-17
- 0.0.1 — 2019-11-16

## README

# Serverless Groovy Plugin

#### Deploy [Groovy](http://groovy-lang.org/) [Lambda](https://aws.amazon.com/lambda/) Functions the EASY way using the [Serverless Framework](https://serverless.com/)

## 📦 Prerequisites

Install [Node](https://www.npmjs.com/get-npm).

Install the [Serverless Framework](https://serverless.com/framework/).

Install **Java** and **Groovy**. The easiest way to install is to use [SDK MAN](https://sdkman.io/):

```bash
➜ curl -s "https://get.sdkman.io" | bash
➜ sdk install java 8.0.222-amzn
➜ sdk install groovy
```

You also need to setup your AWS credentials/profiles in the `~/.aws/credentials` file.

```
[default]
aws_access_key_id = XXXXXXXXXXXXXX
aws_secret_access_key = XXXXXXXXXXXXXX
region = us-east-1
```

## 🛵 Usage

A Serverless Framework template is available here: https://github.com/bytekast/serverless-toolkit/tree/master/templates/serverless-groovy-scripts

To use the template, simply run:
```
➜ serverless create --template-url https://github.com/bytekast/serverless-toolkit/tree/master/templates/serverless-groovy-scripts --path my-api
➜ cd my-api
➜ serverless plugin install -n serverless-groovy
➜ serverless deploy 
```

This plugin also has rudimentary unit tests support.

`serverless groovy test` will run the all the classes that extend `GroovyTestCase` in the workspace.

## 📖 Details

The are many Java/Groovy tools and frameworks that allow developers to deploy serverless functions. However, most of them require complicated setup and build configurations. The intent of this plugin is to make it as simple as possible to use Groovy with Serverless.

It only requires 2 files: the `serverless.yml` configuration file and a `handler.groovy` script that contains your function logic. This makes it as simple as `python` or `nodejs` based Serverless Framework projects.

Here is a sample `serverless.yml` config file:

```yaml
service: serverless-groovy

provider:
  name: aws

functions:
  hello:
    handler: handler::hello

plugins:
  - serverless-groovy

```

The `handler` config above specifies the name of the groovy file (`handler.groovy`) without the `.groovy` extension and the function (`hello`).

Here is the corresponding `handler.groovy` file:

```groovy
def hello(message) {
  return "Hello, ${message}"
}
```

You may even use external dependencies in your handler:

```groovy
@Grab('com.amazonaws:aws-lambda-java-core:1.2.0')
@Grab('com.amazonaws:aws-lambda-java-events:2.2.7')
@Grab('org.codehaus.groovy:groovy-json:2.5.8')

import com.amazonaws.services.lambda.runtime.events.APIGatewayV2ProxyRequestEvent
import com.amazonaws.services.lambda.runtime.events.APIGatewayV2ProxyResponseEvent
import groovy.json.JsonOutput
import groovy.transform.CompileStatic

@CompileStatic
def api(APIGatewayV2ProxyRequestEvent event) {
  final response = new APIGatewayV2ProxyResponseEvent()
  response.setStatusCode(200)
  response.setBody(JsonOutput.prettyPrint(JsonOutput.toJson(event)))
  return response
}
```

> As you can see above, you can enable static typing by annotating your function with `@CompileStatic`

The `serverless.yml` could look like this if you are exposing an http endpoint:

```yaml
service: serverless-groovy

provider:
  name: aws

functions:
  api:
    handler: handler::api
    events:
      - http:
          path: api
          method: get

plugins:
  - serverless-groovy

```


To deploy your service, simply run `serverless deploy`.

The plugin will take care of compiling and packaging your Groovy scripts automatically.

```
Serverless: Packaging service...
Serverless: Excluding development dependencies...
Serverless: Successfully packaged function: hello
Serverless: Successfully packaged function: api
Serverless: Creating Stack...
Serverless: Checking Stack create progress...
........
Serverless: Stack create finished...
Serverless: Uploading CloudFormation file to S3...
Serverless: Uploading artifacts...
Serverless: Uploading service hello.jar file to S3 (6.08 MB)...
Serverless: Uploading service api.jar file to S3 (6.08 MB)...
Serverless: Validating template...
Serverless: Updating Stack...
Serverless: Checking Stack update progress...
.......................................
Serverless: Stack update finished...
Service Information
service: my-api
stage: dev
region: us-east-1
stack: my-api-dev
resources: 14
api keys:
  None
endpoints:
  GET - https://xxxxxxxxxx.execute-api.us-east-1.amazonaws.com/dev/api
functions:
  hello: my-api-dev-hello
  api: my-api-dev-api
layers:
  None
```

#### Voiala!

---
_Source: https://npm.io/package/serverless-groovy · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
