2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

aws-lambda-go/cmd/build-lambda-zipをgo get時のエラー

Last updated at Posted at 2019-11-12

何をしていたか

此方の記事を参考に、sam cliにてgolang, API gateway を試用していたところ、エラーに遭遇しました。

環境

  • windows10 Pro
>sam --version
SAM CLI, version 0.31.0

詳細

ローカル実行は問題無し。API gatewayからRequestしたところ、502エラーが出ました。

もろもろの記事を見ると、build-lambda-zip をbuild時に実行し、zipファイルをS3へuploadすればよさそうです。


build:
        GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o hello-world/hello-world ./hello-world
        ${GOPATH}\bin\build-lambda-zip.exe -o hello-world/hello-world.zip hello-world/hello-world

こちらのbuild-lambda-zip.exe をinstall。

エラー。

>go.exe get -u github.com/aws/aws-lambda-go/cmd/build-lambda-zip
# github.com/aws/aws-lambda-go/cmd/build-lambda-zip
src\github.com\aws\aws-lambda-go\cmd\build-lambda-zip\main.go:19:17: cannot use cli.StringFlag literal (type cli.StringFlag) as type cli.Flag in array or slice literal:
        cli.StringFlag does not implement cli.Flag (Apply method has pointer receiver)

解決策

  1. go get gopkg.in/urfave/cli.v1
  2. src\github.com\aws\aws-lambda-go\cmd\build-lambda-zip\main.go を下記のように変更
  3. go.exe get -u github.com/aws/aws-lambda-go/cmd/build-lambda-zip
import (
	"archive/zip"
	"errors"
	"fmt"
	"io/ioutil"
	"os"
	"path/filepath"

	// "github.com/urfave/cli"
	"gopkg.in/urfave/cli.v1"
)

これで問題なくexeファイルが作成されました。

補遺

最後に、makeファイルを変更し、zipファイルをuploadしてあげます。

build:
	GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o hello-world/hello-world ./hello-world
	${GOPATH}\bin\build-lambda-zip.exe -o hello-world/hello-world.zip hello-world/hello-world
package:
	sam package --template-file template.yaml --output-template-file output-template.yaml --s3-bucket sam-template-store-dev-kubosuke --profile *****

deploy:
	sam deploy --template-file output-template.yaml --stack-name kubosuke --capabilities CAPABILITY_IAM --profile *****

SAMご利用の方は CodeUri: hello-world/hello-world.zip を忘れずに

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?