npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

serverless-groovy

v0.0.4

Published

Serverless Framework Plugin for Groovy

Downloads

7

Readme

Serverless Groovy Plugin

Deploy Groovy Lambda Functions the EASY way using the Serverless Framework

📦 Prerequisites

Install Node.

Install the Serverless Framework.

Install Java and Groovy. The easiest way to install is to use SDK MAN:

➜ 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:

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:

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

You may even use external dependencies in your handler:

@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:

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!