84 lines
3.1 KiB
Markdown
84 lines
3.1 KiB
Markdown
# aws-lambda-alias-update
|
|
|
|
Composite action that updates Lambda function aliases from a Terraform output. Iterates over the `lambda_alias_updates` Terraform output and calls `aws lambda update-alias` for each entry.
|
|
|
|
**Example `lambda-alias-updates` input:**
|
|
|
|
```json
|
|
[
|
|
"{\"alias_name\": \"live\", \"function_name\": \"my-get-product\", \"version\": \"42\"}",
|
|
"{\"alias_name\": \"live\", \"function_name\": \"my-get-category\", \"version\": \"7\"}"
|
|
]
|
|
```
|
|
|
|
## Inputs
|
|
|
|
| Input | Required | Default | Description |
|
|
|-------|----------|---------|-------------|
|
|
| `lambda-alias-updates` | Yes | — | JSON array of Lambda alias update objects (Terraform output: `lambda_alias_updates`). Each element is a JSON-encoded string with `alias_name`, `function_name`, and `version`. |
|
|
|
|
## Usage
|
|
|
|
```yaml
|
|
- name: Update Lambda Aliases
|
|
uses: https://schmalz-git.git.onstackit.cloud/schmalz/shared-actions/aws-lambda-alias-update@aws-lambda-alias-update-v1
|
|
with:
|
|
lambda-alias-updates: ${{ steps.tf-apply.outputs.lambda_alias_updates }}
|
|
```
|
|
|
|
## Terraform Setup
|
|
|
|
- Add the following content to the project
|
|
- Add all Lambda Modules to the `provisioned_lambda_modules` list for which the Function Alias and/or Provisioned Concurrency should be updated
|
|
|
|
**`output.tf`**
|
|
```tf
|
|
locals {
|
|
// List of Lambda Modules that have provisioned concurrency configured.
|
|
// Required to update the aliases of these functions after deployment.
|
|
provisioned_lambda_modules = [
|
|
module.lambda_get_category,
|
|
module.lambda_product_get_full_slug,
|
|
module.lambda_get_product,
|
|
]
|
|
}
|
|
|
|
// Output which allows Updates of Lambda Alias and Provisioned Concurrency
|
|
output "lambda_alias_updates" {
|
|
value = concat([for module in local.provisioned_lambda_modules : "{\"alias_name\": \"${module.lambda_alias_name}\", \"function_name\": \"${module.lambda_name}\", \"version\": \"${module.lambda_version}\" }"])
|
|
}
|
|
|
|
```
|
|
|
|
## Example Usage with other Shared Actions
|
|
|
|
```yml
|
|
jobs:
|
|
deploy-stage:
|
|
name: Build and Deploy to Stage
|
|
runs-on: stackit-ubuntu-22
|
|
steps:
|
|
- name: Apply Terraform
|
|
uses: https://schmalz-git.git.onstackit.cloud/schmalz/shared-actions/terraform-apply@terraform-apply-v1
|
|
id: tf-apply
|
|
with:
|
|
terraform-version: 1.14.9
|
|
workspace: stage
|
|
var-file: stage.tfvars
|
|
jfrog-token: ${{ secrets.JFROG_TOKEN }}
|
|
|
|
- name: Update Lambda Aliases
|
|
uses: https://schmalz-git.git.onstackit.cloud/schmalz/shared-actions/aws-lambda-alias-update@aws-lambda-alias-update-v1
|
|
with:
|
|
lambda-alias-updates: ${{ steps.tf-apply.outputs.lambda_alias_updates }}
|
|
|
|
- name: Wait for Lambda Provisioned Concurrency
|
|
uses: https://schmalz-git.git.onstackit.cloud/schmalz/shared-actions/aws-lambda-wait-for-provisioned-concurrency@aws-lambda-wait-for-provisioned-concurrency-v1
|
|
with:
|
|
lambda-alias-updates: ${{ steps.tf-apply.outputs.lambda_alias_updates }}
|
|
```
|
|
|
|
## Notes
|
|
|
|
- Expects the `lambda-alias-updates` input to be the raw `lambda_alias_updates` output from the `terraform-apply` action.
|
|
- Requires AWS credentials to be configured in the job before this step runs.
|