Skip to content

Commit 7501dbf

Browse files
committed
chore(layer): change layer-balance script to support new regions
1 parent cf3185c commit 7501dbf

File tree

3 files changed

+62
-21
lines changed

3 files changed

+62
-21
lines changed

layer/scripts/layer-balancer/go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,5 @@ require (
2121
github.com/aws/aws-sdk-go-v2/service/sts v1.16.19 // indirect
2222
github.com/aws/smithy-go v1.13.3 // indirect
2323
github.com/jmespath/go-jmespath v0.4.0 // indirect
24+
golang.org/x/exp v0.0.0-20230321023759-10a507213a29 // indirect
2425
)

layer/scripts/layer-balancer/go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHW
3131
github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U=
3232
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
3333
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
34+
golang.org/x/exp v0.0.0-20230321023759-10a507213a29 h1:ooxPy7fPvB4kwsA2h+iBNHkAbp/4JxTSwCmvdjEYmug=
35+
golang.org/x/exp v0.0.0-20230321023759-10a507213a29/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc=
3436
golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o=
3537
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
3638
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=

layer/scripts/layer-balancer/main.go

Lines changed: 59 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"github.com/aws/aws-sdk-go-v2/config"
1616
"github.com/aws/aws-sdk-go-v2/service/lambda"
1717
"github.com/aws/aws-sdk-go-v2/service/lambda/types"
18+
"golang.org/x/exp/slices"
1819
"golang.org/x/sync/errgroup"
1920
)
2021

@@ -44,27 +45,40 @@ var canonicalLayers = []LayerInfo{
4445
// regions are the regions that we want to keep in sync
4546
var regions = []string{
4647
"af-south-1",
47-
"eu-central-1",
48-
"us-east-1",
49-
"us-east-2",
50-
"us-west-1",
51-
"us-west-2",
5248
"ap-east-1",
53-
"ap-south-1",
5449
"ap-northeast-1",
5550
"ap-northeast-2",
51+
"ap-northeast-3",
52+
"ap-south-1",
53+
"ap-south-2",
5654
"ap-southeast-1",
5755
"ap-southeast-2",
56+
"ap-southeast-3",
57+
"ap-southeast-4",
5858
"ca-central-1",
59+
"eu-central-1",
60+
"eu-central-2",
61+
"eu-north-1",
62+
"eu-south-1",
63+
"eu-south-2",
5964
"eu-west-1",
6065
"eu-west-2",
6166
"eu-west-3",
62-
"eu-south-1",
63-
"eu-north-1",
64-
"sa-east-1",
65-
"ap-southeast-3",
66-
"ap-northeast-3",
67+
"me-central-1",
6768
"me-south-1",
69+
"sa-east-1",
70+
"us-east-1",
71+
"us-east-2",
72+
"us-west-1",
73+
"us-west-2",
74+
}
75+
76+
var singleArchitectureRegions = []string{
77+
"ap-south-2",
78+
"ap-southeast-4",
79+
"eu-central-2",
80+
"eu-south-2",
81+
"me-central-1",
6882
}
6983

7084
// getLayerVersion returns the latest version of a layer in a region
@@ -100,6 +114,11 @@ func getGreatestVersion(ctx context.Context) (int64, error) {
100114
layer := &canonicalLayers[idx]
101115

102116
for _, region := range regions {
117+
// Ignore regions that are excluded
118+
if layer.Architecture == types.ArchitectureArm64 && slices.Contains(singleArchitectureRegions, region) {
119+
continue
120+
}
121+
103122
layerName := layer.Name
104123
ctx := ctx
105124
region := region
@@ -149,16 +168,30 @@ func balanceRegionToVersion(ctx context.Context, region string, layer *LayerInfo
149168
return fmt.Errorf("error downloading canonical zip: %w", err)
150169
}
151170

152-
layerVersionResponse, err := lambdaSvc.PublishLayerVersion(ctx, &lambda.PublishLayerVersionInput{
153-
Content: &types.LayerVersionContentInput{
154-
ZipFile: payload,
155-
},
156-
LayerName: aws.String(layer.Name),
157-
CompatibleArchitectures: []types.Architecture{layer.Architecture},
158-
CompatibleRuntimes: []types.Runtime{types.RuntimePython37, types.RuntimePython38, types.RuntimePython39},
159-
Description: aws.String(layer.Description),
160-
LicenseInfo: aws.String("MIT-0"),
161-
})
171+
var layerVersionResponse *lambda.PublishLayerVersionOutput
172+
173+
if slices.Contains(singleArchitectureRegions, region) {
174+
layerVersionResponse, err = lambdaSvc.PublishLayerVersion(ctx, &lambda.PublishLayerVersionInput{
175+
Content: &types.LayerVersionContentInput{
176+
ZipFile: payload,
177+
},
178+
LayerName: aws.String(layer.Name),
179+
CompatibleRuntimes: []types.Runtime{types.RuntimePython37, types.RuntimePython38, types.RuntimePython39},
180+
Description: aws.String(layer.Description),
181+
LicenseInfo: aws.String("MIT-0"),
182+
})
183+
} else {
184+
layerVersionResponse, err = lambdaSvc.PublishLayerVersion(ctx, &lambda.PublishLayerVersionInput{
185+
Content: &types.LayerVersionContentInput{
186+
ZipFile: payload,
187+
},
188+
LayerName: aws.String(layer.Name),
189+
CompatibleArchitectures: []types.Architecture{layer.Architecture},
190+
CompatibleRuntimes: []types.Runtime{types.RuntimePython37, types.RuntimePython38, types.RuntimePython39},
191+
Description: aws.String(layer.Description),
192+
LicenseInfo: aws.String("MIT-0"),
193+
})
194+
}
162195
if err != nil {
163196
return fmt.Errorf("error publishing layer version: %w", err)
164197
}
@@ -186,6 +219,11 @@ func balanceRegions(ctx context.Context, maxVersion int64) error {
186219
layer := &canonicalLayers[idx]
187220

188221
for _, region := range regions {
222+
// Ignore regions that are excluded
223+
if layer.Architecture == types.ArchitectureArm64 && slices.Contains(singleArchitectureRegions, region) {
224+
continue
225+
}
226+
189227
ctx := ctx
190228
region := region
191229
layer := layer

0 commit comments

Comments
 (0)