feat: add aws-lambda-alias-update and aws-lambda-wait-for-provisioned-concurrency actions
This commit is contained in:
parent
3aede0905e
commit
4d9b2459a4
5 changed files with 287 additions and 2 deletions
84
aws-lambda-alias-update/README.md
Normal file
84
aws-lambda-alias-update/README.md
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
# 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.
|
||||
49
aws-lambda-alias-update/action.yml
Normal file
49
aws-lambda-alias-update/action.yml
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
name: "AWS Lambda - Update Alias"
|
||||
description: >
|
||||
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.
|
||||
|
||||
inputs:
|
||||
lambda-alias-updates:
|
||||
description: >
|
||||
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.
|
||||
required: true
|
||||
|
||||
runs:
|
||||
using: "composite"
|
||||
steps:
|
||||
- name: Install AWS CLI
|
||||
shell: bash
|
||||
run: |
|
||||
if ! command -v aws &> /dev/null; then
|
||||
curl -fsSL "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o /tmp/awscliv2.zip
|
||||
unzip -q /tmp/awscliv2.zip -d /tmp
|
||||
sudo /tmp/aws/install
|
||||
rm -rf /tmp/awscliv2.zip /tmp/aws
|
||||
fi
|
||||
|
||||
- name: Install jq if missing
|
||||
shell: bash
|
||||
run: |
|
||||
set -euo pipefail
|
||||
command -v jq >/dev/null 2>&1 || sudo apt-get install -y --no-install-recommends jq
|
||||
|
||||
- name: Update Lambda Aliases
|
||||
shell: bash
|
||||
env:
|
||||
LAMBDA_ALIAS_UPDATES: ${{ inputs.lambda-alias-updates }}
|
||||
run: |
|
||||
echo "$LAMBDA_ALIAS_UPDATES" | jq -c '.[] | fromjson' | while IFS= read -r entry; do
|
||||
alias_name=$(echo "$entry" | jq -r '.alias_name')
|
||||
function_name=$(echo "$entry" | jq -r '.function_name')
|
||||
version=$(echo "$entry" | jq -r '.version')
|
||||
echo "Updating alias '$alias_name' for '$function_name' to version '$version'"
|
||||
aws lambda update-alias \
|
||||
--no-cli-pager \
|
||||
--name "$alias_name" \
|
||||
--function-name "$function_name" \
|
||||
--function-version "$version"
|
||||
echo "Updated alias '$alias_name' for '$function_name' to version '$version'"
|
||||
done
|
||||
Loading…
Add table
Add a link
Reference in a new issue