Skip to content
This repository was archived by the owner on Dec 2, 2020. It is now read-only.

Commit 84a3da7

Browse files
asahasrabuddheclareliguori
authored andcommitted
Support compatible runtimes (#11)
support other compatible runtimes other than 'provided'
1 parent 163733b commit 84a3da7

File tree

4 files changed

+76
-20
lines changed

4 files changed

+76
-20
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ GLOBAL OPTIONS:
3838
--dry-run, -d Conduct a dry-run: Repackage the image, but only write the Lambda layers to local disk (do not publish to Lambda)
3939
--description value, --desc value The description of this layer version (default: "created by img2lambda from image <name of the image>")
4040
--license-info value, -l value The layer's software license. It can be an SPDX license identifier, the URL of the license hosted on the internet, or the full text of the license (default: no license)
41+
--compatible-runtime value --compatible-runtime value,
42+
--cr value --cr value An AWS Lambda function runtime compatible with the image layers. To specify multiple runtimes, repeat the option: --cr provided --cr python2.7 (default: "provided" )
4143
4244
--help, -h show help
4345
```

img2lambda/cli/main.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ func createApp() (*cli.App, *types.CmdOptions) {
2424
app.Version = version.VersionString()
2525
app.Usage = "Repackages a container image into AWS Lambda layers and publishes them to Lambda"
2626
app.Action = func(c *cli.Context) error {
27+
// parse and store the passed runtime list into the options object
28+
opts.CompatibleRuntimes = c.StringSlice("cr")
29+
2730
validateCliOptions(&opts, c)
2831
return repackImageAction(&opts)
2932
}
@@ -66,6 +69,11 @@ func createApp() (*cli.App, *types.CmdOptions) {
6669
Usage: "The layer's software license. It can be an SPDX license identifier, the URL of the license hosted on the internet, or the full text of the license (default: \"no license\"",
6770
Destination: &opts.LicenseInfo,
6871
},
72+
cli.StringSliceFlag{
73+
Name: "compatible-runtime, cr",
74+
Usage: "An AWS Lambda function runtime compatible with the image layers. To specify multiple runtimes, repeat the option: --cr provided --cr python2.7 (default: \"provided\" )",
75+
Value: &cli.StringSlice{},
76+
},
6977
}
7078

7179
app.Setup()
@@ -79,6 +87,13 @@ func validateCliOptions(opts *types.CmdOptions, context *cli.Context) {
7987
fmt.Print("ERROR: Image name is required\n\n")
8088
cli.ShowAppHelpAndExit(context, 1)
8189
}
90+
91+
for _, runtime := range opts.CompatibleRuntimes {
92+
if !types.ValidRuntimes.Contains(runtime) {
93+
fmt.Println("ERROR: Compatible runtimes must be one of the supported runtimes\n\n", types.ValidRuntimes)
94+
cli.ShowAppHelpAndExit(context, 1)
95+
}
96+
}
8297
}
8398

8499
func repackImageAction(opts *types.CmdOptions) error {

img2lambda/publish/publish_layers.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ func PublishLambdaLayers(opts *types.PublishOptions, layers []types.LambdaLayer)
3737
licenseInfo = aws.String(opts.LicenseInfo)
3838
}
3939

40+
if len(opts.CompatibleRuntimes) == 0 {
41+
opts.CompatibleRuntimes = append(opts.CompatibleRuntimes, "provided")
42+
}
43+
4044
layerContents, err := ioutil.ReadFile(layer.File)
4145
if err != nil {
4246
return "", err
@@ -52,7 +56,7 @@ func PublishLambdaLayers(opts *types.PublishOptions, layers []types.LambdaLayer)
5256
log.Printf("Matched Lambda layer file %s (image layer %s) to existing Lambda layer: %s", layer.File, layer.Digest, existingArn)
5357
} else {
5458
publishArgs := &lambda.PublishLayerVersionInput{
55-
CompatibleRuntimes: []*string{aws.String("provided")},
59+
CompatibleRuntimes: aws.StringSlice(opts.CompatibleRuntimes),
5660
Content: &lambda.LayerVersionContentInput{ZipFile: layerContents},
5761
Description: layerDescription,
5862
LayerName: aws.String(layerName),

img2lambda/types/types.go

Lines changed: 54 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,31 +13,66 @@ type LambdaLayer struct {
1313
}
1414

1515
type CmdOptions struct {
16-
Image string // Name of the container image
17-
Region string // AWS region
18-
OutputDir string // Output directory for the Lambda layers
19-
DryRun bool // Dry-run (will not register with Lambda)
20-
LayerNamespace string // Prefix for published Lambda layers
21-
Description string // Description of the current layer version
22-
LicenseInfo string // Layer's software license
16+
Image string // Name of the container image
17+
Region string // AWS region
18+
OutputDir string // Output directory for the Lambda layers
19+
DryRun bool // Dry-run (will not register with Lambda)
20+
LayerNamespace string // Prefix for published Lambda layers
21+
Description string // Description of the current layer version
22+
LicenseInfo string // Layer's software license
23+
CompatibleRuntimes []string // A list of function runtimes compatible with the current layer
2324
}
2425

2526
type PublishOptions struct {
26-
LambdaClient lambdaiface.LambdaAPI
27-
LayerPrefix string
28-
ResultsDir string
29-
SourceImageName string
30-
Description string
31-
LicenseInfo string
27+
LambdaClient lambdaiface.LambdaAPI
28+
LayerPrefix string
29+
ResultsDir string
30+
SourceImageName string
31+
Description string
32+
LicenseInfo string
33+
CompatibleRuntimes []string
3234
}
3335

3436
func ConvertToPublishOptions(opts *CmdOptions) *PublishOptions {
3537
return &PublishOptions{
36-
SourceImageName: opts.Image,
37-
LambdaClient: clients.NewLambdaClient(opts.Region),
38-
LayerPrefix: opts.LayerNamespace,
39-
ResultsDir: opts.OutputDir,
40-
Description: opts.Description,
41-
LicenseInfo: opts.LicenseInfo,
38+
SourceImageName: opts.Image,
39+
LambdaClient: clients.NewLambdaClient(opts.Region),
40+
LayerPrefix: opts.LayerNamespace,
41+
ResultsDir: opts.OutputDir,
42+
Description: opts.Description,
43+
LicenseInfo: opts.LicenseInfo,
44+
CompatibleRuntimes: opts.CompatibleRuntimes,
4245
}
4346
}
47+
48+
// valid aws lambda function runtimes
49+
type Runtimes []string
50+
51+
// utility function to validate if a runtime is valid (supported by aws) or not
52+
func (r Runtimes) Contains(runtime string) bool {
53+
for _, value := range r {
54+
if value == runtime {
55+
return true
56+
}
57+
}
58+
return false
59+
}
60+
61+
// a list of aws supported runtimes as of 26/01/2019
62+
var ValidRuntimes = Runtimes{
63+
"nodejs", // eol = 31/10/2016 but included to support existing versions
64+
"nodejs4.3", // eol = 30/04/2018 but included to support existing versions
65+
"nodejs6.10",
66+
"nodejs8.10",
67+
"java8",
68+
"python2.7",
69+
"python3.6",
70+
"python3.7",
71+
"dotnetcore1.0",
72+
"dotnetcore2.0",
73+
"dotnetcore2.1",
74+
"nodejs4.3-edge", // eol = 30/04/2018 but included to support existing versions
75+
"go1.x",
76+
"ruby2.5",
77+
"provided",
78+
}

0 commit comments

Comments
 (0)