Skip to content
This repository has been archived by the owner on Jun 8, 2022. It is now read-only.

Support golang #33

Open
kurtmaile opened this issue Jan 21, 2019 · 3 comments
Open

Support golang #33

kurtmaile opened this issue Jan 21, 2019 · 3 comments

Comments

@kurtmaile
Copy link

Hi, Is there a version of this that supports go workflow?

Cheers!

@raymondbutcher
Copy link
Contributor

Hi,

Custom build commands were added in v0.11.0. There is an example here which uses Docker: https://github.com/claranet/terraform-aws-lambda/tree/master/tests/build-command

It should be possible to have a build script that runs go build directly or in Docker. I don't currently have a Go project to test this on.

If you get this working, please update this issue and maybe we can add a test for it.

Cheers!

@cabrinha
Copy link

Using version 0.12.0 of this module, I'm trying to deploy a Golang program to Lambda. I keep getting this error:

1 error occurred:
        * module.lambda.aws_lambda_function.lambda: 1 error occurred:
        * aws_lambda_function.lambda: Unable to load ".terraform/modules/e110d05b8a5fda2c10d1162d99c4c426/builds/ef8ee508b96c87890bd6ad1a2d911c97fe8aee277953fdd83cddf4067c8e32ef.zip": open .terraform/modules/e110d05b8a5fda2c10d1162d99c4c426/builds/ef8ee508b96c87890bd6ad1a2d911c97fe8aee277953fdd83cddf4067c8e32ef.zip: no such file or directory

I'm a little confused as to how / where this zip file should be getting created.

If I specify my own build command as go build main.go -o app, should I zip the app binary myself or should I expect this module to zip up that binary for me?

It would be good to get some documentation around what's expected of the module caller in order to deliver a binary for deployment.

@raymondbutcher
Copy link
Contributor

Hi @cabrinha,

Yes, you'll need to create the zip file yourself when using a custom build command, which you'll need to do if you're building a Go binary.

See here in the build-command test/example where it is overriding the build command variable:

build_command = "${path.cwd}/lambda/build.sh '$filename' '$runtime' '$source'"

It passes 3 variables to build.sh, in particular $filename.

Then in build.sh it takes the $FILENAME argument (which was $1, the first argument) to come up with $ZIP_DIR and $ZIP_NAME:

ZIP_DIR=$(cd "$(dirname "$FILENAME")" && pwd)
ZIP_NAME=$(basename "$FILENAME")

And ends up writing a zip file to that path:

I guess it's not so obvious because it splits the directory and filename. It has to do that in this example so it can mount the directory as a volume in Docker.

You should be able to take the build-command test/example and modify it to use a Go docker image and run go build instead of pip install, or remove Docker from the mix if you're happy to rely on the Go toolchain being installed on the host (this is not my preferred option because it becomes harder for me to test it).

If you do get this working, please share the code or submit a PR with a new test/example.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants