Skip to content

Commit

Permalink
modify env vars
Browse files Browse the repository at this point in the history
  • Loading branch information
chaudharysaket committed Mar 19, 2024
1 parent 2bcaf9e commit 33e0bad
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 9 deletions.
19 changes: 19 additions & 0 deletions local_testing/delete_infra.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash

# Variables
REGION="us-west-2" # Preferred AWS region

runtimes=("python3.11" "python3.12")
architectures=("x86_64" "arm64")

for arch in "${architectures[@]}"; do
for runtime in "${runtimes[@]}"; do
FUNCTION_NAME_SUFFIX="${arch}_${runtime//./}"
FUNCTION_NAME="NR_EXTENSION_TEST_LAMBDA_${FUNCTION_NAME_SUFFIX}"
if aws lambda delete-function --function-name "$FUNCTION_NAME" --region "$REGION"; then
echo "Successfully deleted $FUNCTION_NAME"
else
echo "Failed to delete $FUNCTION_NAME"
fi
done
done
11 changes: 11 additions & 0 deletions local_testing/environment.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"Variables": {
"NEW_RELIC_ACCOUNT_ID": "",
"NEW_RELIC_EXTENSION_SEND_FUNCTION_LOGS": "",
"NEW_RELIC_LAMBDA_EXTENSION_ENABLED": "",
"NEW_RELIC_LAMBDA_HANDLER": "lambda_function.lambda_handler",
"NEW_RELIC_LICENSE_KEY": "",
"NEW_RELIC_LOG_ENDPOINT": "",
"NEW_RELIC_TELEMETRY_ENDPOINT": ""
}
}
11 changes: 2 additions & 9 deletions local_testing/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,13 @@ REGION="us-west-2" # Preferred AWS region
TRUST_POLICY="trust-policy.json"
lambda_result_file="lambda_output.txt"

NEW_RELIC_ACCOUNT_ID="${NEW_RELIC_ACCOUNT_ID}"
NEW_RELIC_LAMBDA_EXTENSION_ENABLED="True"
NEW_RELIC_LAMBDA_HANDLER="${NEW_RELIC_LAMBDA_HANDLER}"
NEW_RELIC_LICENSE_KEY_SECRET="${NEW_RELIC_LICENSE_KEY_SECRET}"
NEW_RELIC_LOG_ENDPOINT="${NEW_RELIC_LOG_ENDPOINT}"
NEW_RELIC_TELEMETRY_ENDPOINT="${NEW_RELIC_TELEMETRY_ENDPOINT}"

source nr_tmp_env.sh

zip function.zip function.py

role_exists=$(aws iam get-role --role-name "$ROLE_NAME" --query 'Role.Arn' --output text --region "$REGION" 2>&1)
if [[ $role_exists == arn:aws:iam::* ]]; then
echo "IAM role already exists."
echo "IAM role $ROLE_NAME already exists."
EXECUTION_ROLE_ARN=$role_exists
else
EXECUTION_ROLE_ARN=$(aws iam create-role --role-name "$ROLE_NAME" --assume-role-policy-document "file://$TRUST_POLICY" --query 'Role.Arn' --output text --region "$REGION")
Expand Down Expand Up @@ -65,7 +58,7 @@ for arch in "${architectures[@]}"; do
--architectures "$arch" \
--role "$EXECUTION_ROLE_ARN" \
--layers "$final_layer_arn" \
--environment Variables="{NEW_RELIC_ACCOUNT_ID=$NEW_RELIC_ACCOUNT_ID,NEW_RELIC_LAMBDA_EXTENSION_ENABLED=$NEW_RELIC_LAMBDA_EXTENSION_ENABLED,NEW_RELIC_LAMBDA_HANDLER=$NEW_RELIC_LAMBDA_HANDLER,NEW_RELIC_LICENSE_KEY_SECRET=$NEW_RELIC_LICENSE_KEY_SECRET,NEW_RELIC_LOG_ENDPOINT=$NEW_RELIC_LOG_ENDPOINT,NEW_RELIC_TELEMETRY_ENDPOINT=$NEW_RELIC_TELEMETRY_ENDPOINT}" \
--environment file://environment.json \
--query 'FunctionArn' \
--output text \
--region "$REGION")
Expand Down

0 comments on commit 33e0bad

Please sign in to comment.