# serverless-plugin-go

> Serverless Framework plugin that compiles Go functions on the fly

Latest version **0.1.2** (published 2026-03-31) · MIT license · 0 weekly downloads

## Install

```sh
npm install serverless-plugin-go
pnpm add serverless-plugin-go
yarn add serverless-plugin-go
bun add serverless-plugin-go
```

## Health

**Score 55/100 (C)** — status: active.

Positive: esm support; no vulnerabilities; has provenance.

Warnings: low downloads; no types; pre 1.0.

## Facts

| | |
|---|---|
| Version | 0.1.2 |
| Published | 2026-03-31 |
| First published | 2023-10-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 5 |
| Unpacked size | 35.3 KB |
| Known vulnerabilities | 0 (+3 in 1 direct dependencies) |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 4 |
| Author | Maciej Winnicki |
| Maintainers | draftea-infra |
| Keywords | serverless, serverless framework, serverless plugin, amazon web services, aws, lambda, golang, go |

## Links

- npm: https://www.npmjs.com/package/serverless-plugin-go
- Repository: https://github.com/Drafteame/serverless-plugin-go
- Homepage: https://github.com/Drafteame/serverless-plugin-go#readme
- Issues: https://github.com/Drafteame/serverless-plugin-go/issues
- npm.io page: https://npm.io/package/serverless-plugin-go

## Dependencies (5)

- [util](https://npm.io/package/util.md) ^0.12.5
- [chalk](https://npm.io/package/chalk.md) ^5.3.0
- [adm-zip](https://npm.io/package/adm-zip.md) ^0.5.10
- [p-limit](https://npm.io/package/p-limit.md) ^5.0.0
- [pretty-hrtime](https://npm.io/package/pretty-hrtime.md) ^1.0.3

## Alternatives

- [angular-pipes](https://npm.io/package/angular-pipes.md) — 5.6K weekly downloads
- [@ng-web-apis/midi](https://npm.io/package/@ng-web-apis/midi.md) — 2.6K weekly downloads
- [happn-3](https://npm.io/package/happn-3.md) — 1.6K weekly downloads
- [@opensip-cli/lang-go](https://npm.io/package/@opensip-cli/lang-go.md) — 1.2K weekly downloads
- [mongoose-typescript](https://npm.io/package/mongoose-typescript.md) — 85 weekly downloads

## Recent versions

- 0.1.2 (latest) — 2026-03-31
- 0.1.1 — 2026-01-21
- 0.1.0 — 2025-08-12
- 0.0.3 — 2024-08-19
- 0.0.2 — 2023-11-16
- 0.0.1 — 2023-10-26

## README

# ⚡️Serverless Framework Go Plugin

[![npm](https://img.shields.io/npm/v/serverless-plugin-go)](https://www.npmjs.com/package/serverless-plugin-go)

`serverless-plugin-go` is a Serverless Framework plugin that compiles Go functions on the fly. You don't need to do it manually before `serverless deploy`. Once the plugin is installed it will happen automatically.

## Features

- Concurrent compilation happens across all CPU cores.
- Support for both `serverless deploy` and `serverless deploy function` commands.
- Support for `serverless invoke local` command.
- Additional command `serverless go build`.

## Install

1. Install the plugin

    ```bash
    npm i --save-dev serverless-plugin-go
    ```

1. Add it to your `serverless.yaml`

    ```yaml
    plugins:
      - 'serverless-plugin-go'
    ```

1. Replace every Go function's `handler` with `*.go` file path or a package path. E.g.

    ```yaml
    functions:
      example:
        runtime: 'provided.al2023' # or provided.al2
        handler: 'functions/example/main.go' # or just functions/example
    ```

## Configuration

Default values:

```yaml
custom:
  go:
    # folder where go.mod file lives, if set `handler` property should be set relatively to that folder
    baseDir: '.'

    # Final target destination of the binary outputs
    binDir: '.bin'

    # Compile command that should be used to build binaries
    cmd: 'go build -ldflags="-s -w"'

    # If enabled, builds function every directory (useful for monorepo where go.mod is managed by each function
    monorepo: false

    # Number of concurrent process used to compile functions, you can fine tune this number to your needs.
    # Alternatively you can use the env var `SP_GO_CONCURRENCY` to override this configuration
    concurrency: 5

    # Environment variables used to compile binaries
    env:
      GOOS: 'linux' # Default compile OS
      CGO_ENABLED: '0' # By default CGO is disabled
      
    # Bash commands to execute before compilation
    # These commands will be executed once before all compilations
    beforeBuild: []
```

### How does it work?

The plugin compiles every Go function defined in `serverless.yaml` into `.bin` directory. After that it internally changes `handler` so
that the Serverless Framework will deploy the compiled file not the source file.

For every matched function it also overrides `package` parameter to the next config:

```yaml
individually: true
artifact: <path to the generated zip with go binary>
```

### How to run Golang Lambda on ARM?

Change architecture field from `provider` or function configuration to `arm64`:

```yaml
provider:
  architecture: 'arm64'
  runtime: 'provided.al2023' # or provided.al2

# If you define architecture at function level, this will have preference instead the provider configuration

functions:
  test:
    architecture: 'arm64'
    handler: test/main.go
```

### How to execute commands before compilation?

You can define bash commands to be executed before any compilation action using the `beforeBuild` configuration:

```yaml
custom:
  go:
    beforeBuild:
      - 'go generate ./...'
      - 'go mod tidy'
```

These commands will be executed once before all compilations, not for each function individually. This applies whether you're using `serverless deploy`, `serverless deploy function`, or `serverless invoke local`.

## Caveats

This implementation doesn't allow to add any other files to the lambda artifact apart from the binary. To address this problem you should
use Lambda Layers to allow your lambdas to hold external files.

## Credits

This repo is forked from [serverless-go-plugin][1] created by [mthenw][2] and modified to fix some issues and reach the new AWS standards
(go1.x provider deprecation).

[1]: https://github.com/mthenw/serverless-go-plugin
[2]: https://github.com/mthenw

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