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

Commit

Permalink
Merge pull request #3282 from hashicorp/kevin/lambda-static-environment
Browse files Browse the repository at this point in the history
feat(aws-lambda): `static_environment`
  • Loading branch information
briancain authored May 19, 2022
2 parents 4e8ba94 + a9f892b commit 308626a
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .changelog/3282.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:improvement
plugin/lambda: Add `static_environment` to deploy plugin
```
44 changes: 44 additions & 0 deletions builtin/aws/lambda/platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,11 @@ func (p *Platform) Deploy(
storage = DefaultStorageSize
}

envVars := make(map[string]*string)
for k, v := range p.config.StaticEnvVars {
envVars[k] = aws.String(v)
}

step.Done()

step = sg.Add("Reading Lambda function: %s", src.App)
Expand Down Expand Up @@ -333,6 +338,25 @@ func (p *Platform) Deploy(
reset = true
}

// if the lambda has no env vars, Environment will be nil
if curFunc.Configuration.Environment != nil {
// compare config to AWS
if !reflect.DeepEqual(envVars, curFunc.Configuration.Environment.Variables) {
update.Environment = &lambda.Environment{
Variables: envVars,
}
reset = true
}
} else {
// only update if we have any envVars to set
if len(envVars) > 0 {
update.Environment = &lambda.Environment{
Variables: envVars,
}
reset = true
}
}

if reset {
step.Update("Detected a configuration change. Updating Lambda function...")

Expand Down Expand Up @@ -419,6 +443,9 @@ func (p *Platform) Deploy(
},
ImageConfig: &lambda.ImageConfig{},
Architectures: aws.StringSlice([]string{architecture}),
Environment: &lambda.Environment{
Variables: envVars,
},
})

if err != nil {
Expand Down Expand Up @@ -902,6 +929,17 @@ deploy {
docs.Default("512"),
)

doc.SetField(
"static_environment",
"environment variables to expose to the lambda function",
docs.Summary(
"environment variables that are meant to configure the application in a static",
"way. This might be to control an image that has multiple modes of operation,",
"selected via environment variable. Most configuration should use the waypoint",
"config commands.",
),
)

return doc, nil
}

Expand Down Expand Up @@ -933,6 +971,12 @@ type Config struct {
// Must be a value between 512 and 10240.
// Defaults to 512 MB.
StorageMB int `hcl:"storagemb,optional"`

// Environment variables that are meant to configure the application in a static
// way. This might be control an image that has multiple modes of operation,
// selected via environment variable. Most configuration should use the waypoint
// config commands.
StaticEnvVars map[string]string `hcl:"static_environment,optional"`
}

var (
Expand Down
4 changes: 4 additions & 0 deletions builtin/aws/lambda/plugin.proto
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,8 @@ message Deployment {

// The version identifier AWS uses for this version (basically a serial increasing number)
string version = 7;

// The storage size (in MB) of the Lambda function's `/tmp` directory.
// Must be a value between 512 and 10240.
int64 storage = 8;
}
9 changes: 9 additions & 0 deletions website/content/partials/components/platform-aws-lambda.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ The amount of memory, in megabytes, to assign the function.
- **Optional**
- Default: 265

#### static_environment

Environment variables to expose to the lambda function.

Environment variables that are meant to configure the application in a static way. This might be to control an image that has multiple modes of operation, selected via environment variable. Most configuration should use the waypoint config commands.

- Type: **map of string to string**
- **Optional**

#### storagemb

The storage size (in MB) of the Lambda function's `/tmp` directory. Must be a value between 512 and 10240.
Expand Down

1 comment on commit 308626a

@vercel
Copy link

@vercel vercel bot commented on 308626a May 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

waypoint-ui – ./ui

waypoint-ui-git-main-hashicorp.vercel.app
waypoint-ui-hashicorp.vercel.app
waypoint-ui.vercel.app

Please sign in to comment.