Skip to content

Commit 9ff9cd1

Browse files
committed
fix #1363 build lambda bin from src instead using a blob + bump ext pkg.
1 parent 5686dc5 commit 9ff9cd1

File tree

5 files changed

+36
-9
lines changed

5 files changed

+36
-9
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-2
Original file line numberDiff line numberDiff line change
@@ -272,8 +272,8 @@ github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj
272272
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio=
273273
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs=
274274
github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY=
275-
github.com/aws/aws-lambda-go v1.13.3 h1:SuCy7H3NLyp+1Mrfp+m80jcbi9KYWAs9/BXwppwRDzY=
276-
github.com/aws/aws-lambda-go v1.13.3/go.mod h1:4UKl9IzQMoD+QF79YdCuzCwp8VbmG4VAQwij/eHl5CU=
275+
github.com/aws/aws-lambda-go v1.47.0 h1:0H8s0vumYx/YKs4sE7YM0ktwL2eWse+kfopsRI1sXVI=
276+
github.com/aws/aws-lambda-go v1.47.0/go.mod h1:dpMpZgvWx5vuQJfBt0zqBha60q7Dd7RfgJv23DymV8A=
277277
github.com/aws/aws-sdk-go v1.15.11/go.mod h1:mFuSZ37Z9YOHbQEwBWztmVzqXrEkub65tZoCYDt7FT0=
278278
github.com/aws/aws-sdk-go v1.44.122 h1:p6mw01WBaNpbdP2xrisz5tIkcNwzj/HysobNoaAHjgo=
279279
github.com/aws/aws-sdk-go v1.44.122/go.mod h1:y4AeaBuwd2Lk+GepC1E9v0qOiTws0MIWAX4oIKwKHZo=

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)