generated from nullplatform/technology-templates-any
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlambda_function_name
More file actions
35 lines (29 loc) · 1.42 KB
/
lambda_function_name
File metadata and controls
35 lines (29 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/bin/bash
# Derives Lambda resource names from CONTEXT or AWS.
# Usage: source "$SERVICE_PATH/utils/lambda_function_name"
# Requires: SCOPE_ID set
# Exports: LAMBDA_FUNCTION_NAME, LAMBDA_LOG_GROUP_NAME
_application_slug=$(echo "$CONTEXT" | jq -r '.application.slug // ""')
_scope_slug=$(echo "$CONTEXT" | jq -r '.scope.slug // ""')
if [ -n "$_application_slug" ] && [ -n "$_scope_slug" ]; then
# Lifecycle contexts (create/update/delete) include full application info.
LAMBDA_FUNCTION_NAME="${SCOPE_ID}-${_application_slug}-${_scope_slug}"
LAMBDA_FUNCTION_NAME="${LAMBDA_FUNCTION_NAME:0:64}"
else
# Action contexts (log/metric/instance/diagnose) may omit application info.
# Look up the function by the scope-id tag set by Terraform.
_lambda_arn=$(aws resourcegroupstaggingapi get-resources \
--tag-filters "Key=nullplatform:scope-id,Values=${SCOPE_ID}" \
--resource-type-filters lambda:function \
--query "ResourceTagMappingList[0].ResourceARN" \
--output text 2>/dev/null || echo "")
if [ -n "$_lambda_arn" ] && [ "$_lambda_arn" != "None" ]; then
LAMBDA_FUNCTION_NAME="${_lambda_arn##*:function:}"
fi
fi
# Log group name follows the AWS Lambda convention, matching the Terraform
# resource in deployment/compute/lambda/modules/locals.tf
LAMBDA_LOG_GROUP_NAME="/aws/lambda/${LAMBDA_FUNCTION_NAME}"
export LAMBDA_FUNCTION_NAME
export LAMBDA_LOG_GROUP_NAME
unset _application_slug _scope_slug _lambda_arn