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

Commit

Permalink
feat(aws-lambda): support architecture
Browse files Browse the repository at this point in the history
  • Loading branch information
thiskevinwang committed Feb 17, 2022
1 parent 2670c4a commit 38ee485
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 8 deletions.
3 changes: 3 additions & 0 deletions .changelog/3032.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:improvements
plugin/aws-lambda: add support for lambda `architecture` ("x86_64" or "arm64")
```
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ bin/entrypoint: # create the entrypoint for the current platform

.PHONY: install
install: bin # build and copy binaries to $GOPATH/bin/waypoint
rm $(GOPATH)/bin/waypoint
mkdir -p $(GOPATH)/bin
cp ./waypoint $(GOPATH)/bin/waypoint

Expand Down
37 changes: 34 additions & 3 deletions builtin/aws/lambda/platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ const (

// How long the function should run before terminating it.
DefaultTimeout = 60

// The instruction set architecture that the function supports.
DefaultArchitecture = lambda.ArchitectureX8664
)

const lambdaRolePolicy = `{
Expand Down Expand Up @@ -233,6 +236,11 @@ func (p *Platform) Deploy(
timeout = DefaultTimeout
}

architecture := p.config.Architecture
if architecture == "" {
architecture = DefaultArchitecture
}

step.Done()

step = sg.Add("Reading Lambda function: %s", src.App)
Expand Down Expand Up @@ -271,11 +279,22 @@ func (p *Platform) Deploy(
}

funcCfg, err := lamSvc.UpdateFunctionCode(&lambda.UpdateFunctionCodeInput{
FunctionName: aws.String(src.App),
ImageUri: aws.String(img.Name()),
FunctionName: aws.String(src.App),
ImageUri: aws.String(img.Name()),
Architectures: aws.StringSlice([]string{architecture}),
})

if err != nil {
if aerr, ok := err.(awserr.Error); ok {
switch aerr.Code() {
case "ValidationException":
// likely here if Architectures was invalid
if architecture != lambda.ArchitectureX8664 && architecture != lambda.ArchitectureArm64 {
return nil, fmt.Errorf("architecture must be either x86_64 or arm64")
}
return nil, err
}
}
return nil, err
}

Expand Down Expand Up @@ -305,7 +324,8 @@ func (p *Platform) Deploy(
Code: &lambda.FunctionCode{
ImageUri: aws.String(img.Name()),
},
ImageConfig: &lambda.ImageConfig{},
ImageConfig: &lambda.ImageConfig{},
Architectures: aws.StringSlice([]string{architecture}),
})

if err != nil {
Expand All @@ -314,6 +334,12 @@ func (p *Platform) Deploy(
switch aerr.Code() {
case "ResourceConflictException":
return nil, err
case "ValidationException":
// likely here if Architectures was an invalid
if architecture != lambda.ArchitectureX8664 && architecture != lambda.ArchitectureArm64 {
return nil, fmt.Errorf("architecture must be either x86_64 or arm64")
}
return nil, err
}
}

Expand Down Expand Up @@ -792,6 +818,11 @@ type Config struct {
// The number of seconds to wait for a function to complete it's work.
// Defaults to 256
Timeout int `hcl:"timeout,optional"`

// The instruction set architecture that the function supports.
// Valid values are: "x86_64", "arm64"
// Defaults to "x86_64".
Architecture string `hcl:"architecture,optional"`
}

var (
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ require (
github.com/DataDog/opencensus-go-exporter-datadog v0.0.0-20210527074920-9baf37265e83
github.com/adrg/xdg v0.2.1
github.com/armon/circbuf v0.0.0-20190214190532-5111143e8da2
github.com/aws/aws-sdk-go v1.36.31
github.com/aws/aws-sdk-go v1.43.0
github.com/bmatcuk/doublestar v1.1.5
github.com/buildpacks/pack v0.20.0
github.com/cenkalti/backoff/v4 v4.0.2
Expand Down Expand Up @@ -302,7 +302,7 @@ require (
go.starlark.net v0.0.0-20200707032745-474f21a9602d // indirect
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 // indirect
golang.org/x/mod v0.4.2 // indirect
golang.org/x/net v0.0.0-20210520170846-37e1c6afe023 // indirect
golang.org/x/net v0.0.0-20211216030914-fe4d6282115f // indirect
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d // indirect
golang.org/x/text v0.3.6 // indirect
Expand Down
7 changes: 4 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,8 @@ github.com/aws/aws-sdk-go v1.31.6/go.mod h1:5zCpMtNQVjRREroY7sYe8lOMRSxkhG6MZveU
github.com/aws/aws-sdk-go v1.31.9/go.mod h1:5zCpMtNQVjRREroY7sYe8lOMRSxkhG6MZveU8YkpAk0=
github.com/aws/aws-sdk-go v1.33.6/go.mod h1:5zCpMtNQVjRREroY7sYe8lOMRSxkhG6MZveU8YkpAk0=
github.com/aws/aws-sdk-go v1.34.9/go.mod h1:5zCpMtNQVjRREroY7sYe8lOMRSxkhG6MZveU8YkpAk0=
github.com/aws/aws-sdk-go v1.36.31 h1:BMVngapDGAfLBVEVzaSIw3fmJdWx7jOvhLCXgRXbXQI=
github.com/aws/aws-sdk-go v1.36.31/go.mod h1:hcU610XS61/+aQV88ixoOzUoG7v3b31pl2zKMmprdro=
github.com/aws/aws-sdk-go v1.43.0 h1:y4UrPbxU/mIL08qksVPE/nwH9IXuC1udjOaNyhEe+pI=
github.com/aws/aws-sdk-go v1.43.0/go.mod h1:OGr6lGMAKGlG9CVrYnWYDKIyb829c6EVBRjxqjmPepc=
github.com/aybabtme/rgbterm v0.0.0-20170906152045-cc83f3b3ce59/go.mod h1:q/89r3U2H7sSsE2t6Kca0lfwTK8JdoNGS/yzM/4iH5I=
github.com/baiyubin/aliyun-sts-go-sdk v0.0.0-20180326062324-cfa1a18b161f/go.mod h1:AuiFmCCPBSrqvVMvuqFuk0qogytodnVFVSN5CeJB8Gc=
github.com/benbjohnson/clock v1.0.3/go.mod h1:bGMdMPoPVvcYyt1gHDf4J2KE153Yf9BuiUKYMaxlTDM=
Expand Down Expand Up @@ -2103,8 +2103,9 @@ golang.org/x/net v0.0.0-20210316092652-d523dce5a7f4/go.mod h1:RBQZq4jEuRlivfhVLd
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk=
golang.org/x/net v0.0.0-20210510120150-4163338589ed/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20210520170846-37e1c6afe023 h1:ADo5wSpq2gqaCGQWzk7S5vd//0iyyLeAratkEoG5dLE=
golang.org/x/net v0.0.0-20210520170846-37e1c6afe023/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20211216030914-fe4d6282115f h1:hEYJvxw1lSnWIl8X9ofsYMklzaDs90JI2az5YMd4fPM=
golang.org/x/net v0.0.0-20211216030914-fe4d6282115f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/oauth2 v0.0.0-20180724155351-3d292e4d0cdc/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20181017192945-9dcd33a902f4/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
Expand Down

0 comments on commit 38ee485

Please sign in to comment.