Skip to content

Commit 0a3656a

Browse files
committed
fix #1363 build lambda bin from src instead using a blob + bump ext pkg.
1 parent 33c3c13 commit 0a3656a

File tree

5 files changed

+36
-10
lines changed

5 files changed

+36
-10
lines changed
Binary file not shown.

examples/terraform-aws-lambda-example/src/bootstrap.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ type Event struct {
1212
Echo string `json:"Echo"`
1313
}
1414

15-
// Fails if ShouldFail is `true`, otherwise echos the input.
15+
// HandleRequest Fails if ShouldFail is `true`, otherwise echos the input.
1616
func HandleRequest(ctx context.Context, evnt *Event) (string, error) {
1717
if evnt == nil {
1818
return "", fmt.Errorf("received nil event")
1919
}
2020
if evnt.ShouldFail {
21-
return "", fmt.Errorf("Failed to handle %#v", evnt)
21+
return "", fmt.Errorf("failed to handle %#v", evnt)
2222
}
2323
return evnt.Echo, nil
2424
}

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ require (
1010
github.com/Azure/go-autorest/autorest/azure/auth v0.5.8
1111
github.com/Azure/go-autorest/autorest/to v0.4.0 // indirect
1212
github.com/Azure/go-autorest/autorest/validation v0.3.1 // indirect
13-
github.com/aws/aws-lambda-go v1.13.3
13+
github.com/aws/aws-lambda-go v1.47.0
1414
github.com/aws/aws-sdk-go v1.44.122
1515
github.com/ghodss/yaml v1.0.0
1616
github.com/go-errors/errors v1.0.2-0.20180813162953-d98b870cc4e0 // indirect

go.sum

+2-3
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,8 @@ github.com/apparentlymart/go-textseg/v15 v15.0.0 h1:uYvfpb3DyLSCGWnctWKGj857c6ew
250250
github.com/apparentlymart/go-textseg/v15 v15.0.0/go.mod h1:K8XmNZdhEBkdlyDdvbmmsvpAG721bKi0joRfFdHIWJ4=
251251
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio=
252252
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs=
253-
github.com/aws/aws-lambda-go v1.13.3 h1:SuCy7H3NLyp+1Mrfp+m80jcbi9KYWAs9/BXwppwRDzY=
254-
github.com/aws/aws-lambda-go v1.13.3/go.mod h1:4UKl9IzQMoD+QF79YdCuzCwp8VbmG4VAQwij/eHl5CU=
253+
github.com/aws/aws-lambda-go v1.47.0 h1:0H8s0vumYx/YKs4sE7YM0ktwL2eWse+kfopsRI1sXVI=
254+
github.com/aws/aws-lambda-go v1.47.0/go.mod h1:dpMpZgvWx5vuQJfBt0zqBha60q7Dd7RfgJv23DymV8A=
255255
github.com/aws/aws-sdk-go v1.44.122 h1:p6mw01WBaNpbdP2xrisz5tIkcNwzj/HysobNoaAHjgo=
256256
github.com/aws/aws-sdk-go v1.44.122/go.mod h1:y4AeaBuwd2Lk+GepC1E9v0qOiTws0MIWAX4oIKwKHZo=
257257
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d h1:xDfNPAt8lFiC1UJrqV3uuy861HCTo708pDMbjHHdCas=
@@ -649,7 +649,6 @@ github.com/tmccombs/hcl2json v0.6.4 h1:/FWnzS9JCuyZ4MNwrG4vMrFrzRgsWEOVi+1AyYUVL
649649
github.com/tmccombs/hcl2json v0.6.4/go.mod h1:+ppKlIW3H5nsAsZddXPy2iMyvld3SHxyjswOZhavRDk=
650650
github.com/ulikunitz/xz v0.5.10 h1:t92gobL9l3HE202wg3rlk19F6X+JOxl9BBrCCMYEYd8=
651651
github.com/ulikunitz/xz v0.5.10/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
652-
github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
653652
github.com/urfave/cli v1.22.2/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
654653
github.com/urfave/cli v1.22.12/go.mod h1:sSBEIC79qR6OvcmsD4U3KABeOTxDqQtdDnaFuUN30b8=
655654
github.com/urfave/cli v1.22.16 h1:MH0k6uJxdwdeWQTwhSO42Pwr4YLrNLwBtg1MRgTqPdQ=

test/terraform_aws_lambda_example_test.go

+31-4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66

77
"github.com/gruntwork-io/terratest/modules/aws"
88
"github.com/gruntwork-io/terratest/modules/random"
9+
"github.com/gruntwork-io/terratest/modules/shell"
910
"github.com/gruntwork-io/terratest/modules/terraform"
1011
test_structure "github.com/gruntwork-io/terratest/modules/test-structure"
1112
"github.com/stretchr/testify/assert"
@@ -20,6 +21,9 @@ func TestTerraformAwsLambdaExample(t *testing.T) {
2021
// against the same terraform module.
2122
exampleFolder := test_structure.CopyTerraformFolderToTemp(t, "../", "examples/terraform-aws-lambda-example")
2223

24+
err := buildLambdaBinary(t, exampleFolder)
25+
require.NoError(t, err)
26+
2327
// Give this lambda function a unique ID for a name so we can distinguish it from any other lambdas
2428
// in your AWS account
2529
functionName := fmt.Sprintf("terratest-aws-lambda-example-%s", random.UniqueId())
@@ -53,14 +57,34 @@ func TestTerraformAwsLambdaExample(t *testing.T) {
5357
assert.Equal(t, `"hi!"`, string(response))
5458

5559
// Invoke the function, this time causing it to error and capturing the error
56-
_, err := aws.InvokeFunctionE(t, awsRegion, functionName, ExampleFunctionPayload{ShouldFail: true, Echo: "hi!"})
60+
_, err = aws.InvokeFunctionE(t, awsRegion, functionName, ExampleFunctionPayload{ShouldFail: true, Echo: "hi!"})
5761

5862
// Function-specific errors have their own special return
5963
functionError, ok := err.(*aws.FunctionError)
6064
require.True(t, ok)
6165

6266
// Make sure the function-specific error comes back
63-
assert.Contains(t, string(functionError.Payload), "Failed to handle")
67+
assert.Contains(t, string(functionError.Payload), "failed to handle")
68+
}
69+
70+
func buildLambdaBinary(t *testing.T, tempDir string) error {
71+
cmd := shell.Command{
72+
Command: "go",
73+
Args: []string{
74+
"build",
75+
"-o",
76+
tempDir + "/src/bootstrap",
77+
tempDir + "/src/bootstrap.go",
78+
},
79+
Env: map[string]string{
80+
"GOOS": "linux",
81+
"GOARCH": "amd64",
82+
"CGO_ENABLED": "0",
83+
},
84+
}
85+
86+
_, err := shell.RunCommandAndGetOutputE(t, cmd)
87+
return err
6488
}
6589

6690
// Another example of how to test the Terraform module in
@@ -73,6 +97,9 @@ func TestTerraformAwsLambdaWithParamsExample(t *testing.T) {
7397
// against the same terraform module.
7498
exampleFolder := test_structure.CopyTerraformFolderToTemp(t, "../", "examples/terraform-aws-lambda-example")
7599

100+
err := buildLambdaBinary(t, exampleFolder)
101+
require.NoError(t, err)
102+
76103
// Give this lambda function a unique ID for a name so we can distinguish it from any other lambdas
77104
// in your AWS account
78105
functionName := fmt.Sprintf("terratest-aws-lambda-withparams-example-%s", random.UniqueId())
@@ -118,13 +145,13 @@ func TestTerraformAwsLambdaWithParamsExample(t *testing.T) {
118145
InvocationType: &invocationType,
119146
Payload: ExampleFunctionPayload{ShouldFail: true, Echo: "hi!"},
120147
}
121-
out, err := aws.InvokeFunctionWithParamsE(t, awsRegion, functionName, input)
148+
out, err = aws.InvokeFunctionWithParamsE(t, awsRegion, functionName, input)
122149

123150
// The Lambda executed, but should have failed.
124151
assert.Error(t, err, "Unhandled")
125152

126153
// Make sure the function-specific error comes back
127-
assert.Contains(t, string(out.Payload), "Failed to handle")
154+
assert.Contains(t, string(out.Payload), "failed to handle")
128155

129156
// Call InvokeFunctionWithParamsE with a LambdaOptions struct that has
130157
// an unsupported InvocationType. The function should fail.

0 commit comments

Comments
 (0)