From 155556aa8adc393cc619d3e36ce40b56c649d63f Mon Sep 17 00:00:00 2001 From: Stephen Cox Date: Tue, 12 Aug 2025 10:45:58 +1200 Subject: [PATCH 1/3] Update to include an optional SAM config file when deploying and split the SAM deploy command across mulitple lines for readability. --- publish_lambda.sh | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/publish_lambda.sh b/publish_lambda.sh index c9206041..299ba701 100755 --- a/publish_lambda.sh +++ b/publish_lambda.sh @@ -8,7 +8,7 @@ set -e echo " AWS CLI (https://aws.amazon.com/cli/), SAM (https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/install-sam-cli.html), Docker and Python3.12 with pip3 required" echo " Please, before launching the tool execute \"$ pip3 install ruamel.yaml\"" -if [ $# -lt 5 ] || [ $# -gt 6 ] +if [ $# -lt 5 ] || [ $# -gt 7 ] then echo "Usage: $0 config-path lambda-name forwarder-tag bucket-name region [custom-role-prefix]" echo " Arguments:" @@ -21,6 +21,7 @@ then echo " region: region where to publish in" echo " custom-role-prefix: role/policy prefix to add in case customization is needed (optional)" echo " (please note that the prefix will be added to both role/policy names)" + echo " config-file: path to the SAM configuration file (optional)" exit 1 fi @@ -31,6 +32,7 @@ TAG_NAME="$3" BUCKET="$4" REGION="$5" CUSTOM_ROLE_PREFIX="${6:-}" ## Default value would be of '' will be passed if this variable is NOT set. +EXPORTER_SAMCONFIG_FILE="${7:-}" ## Default value would be of '' will be passed if this variable is NOT set. TMPDIR=$(mktemp -d /tmp/publish.XXXXXXXXXX) CLONED_FOLDER="${TMPDIR}/sources" @@ -529,6 +531,33 @@ EOF sed -e "s|%codeUri%|${PACKAGE_FOLDER}|g" "${TMPDIR}/publish-before-sed.yaml" > "${TMPDIR}/publish.yaml" python "${TMPDIR}/publish.py" "${PUBLISH_CONFIG}" "${TMPDIR}/publish.yaml" +if [ -n "${EXPORTER_SAMCONFIG_FILE}" ]; then + # copy in the SAM config file if it was specified on the command line + cp "${EXPORTER_SAMCONFIG_FILE}" "${TMPDIR}/" +fi + sam build --debug --use-container --build-dir "${TMPDIR}/.aws-sam/build/publish" --template-file "${TMPDIR}/publish.yaml" --region "${REGION}" -sam package --template-file "${TMPDIR}/.aws-sam/build/publish/template.yaml" --output-template-file "${TMPDIR}/.aws-sam/build/publish/packaged.yaml" --s3-bucket "${BUCKET}" --region "${REGION}" -sam deploy --stack-name "${LAMBDA_NAME}" --capabilities CAPABILITY_NAMED_IAM --template "${TMPDIR}/.aws-sam/build/publish/packaged.yaml" --s3-bucket "${BUCKET}" --region "${REGION}" +sam package --force-upload --template-file "${TMPDIR}/.aws-sam/build/publish/template.yaml" --output-template-file "${TMPDIR}/.aws-sam/build/publish/packaged.yaml" --s3-bucket "${BUCKET}" --region "${REGION}" +SAM_DEPLOY_CMD="sam deploy" +SAM_DEPLOY_CMD="${SAM_DEPLOY_CMD} --stack-name \"${LAMBDA_NAME}\"" +SAM_DEPLOY_CMD="${SAM_DEPLOY_CMD} --capabilities CAPABILITY_NAMED_IAM" +SAM_DEPLOY_CMD="${SAM_DEPLOY_CMD} --template \"${TMPDIR}/.aws-sam/build/publish/packaged.yaml\"" +SAM_DEPLOY_CMD="${SAM_DEPLOY_CMD} --s3-bucket \"${BUCKET}\"" +SAM_DEPLOY_CMD="${SAM_DEPLOY_CMD} --region \"${REGION}\"" +# Comment or uncomment either of the following two lines to support interactive or headless execution mode +# This could be controlled by another optional script argument +#SAM_DEPLOY_CMD="${SAM_DEPLOY_CMD} --confirm-changeset" +SAM_DEPLOY_CMD="${SAM_DEPLOY_CMD} --no-confirm-changeset" +# For CI/CD if there is no change it may not be an error +SAM_DEPLOY_CMD="${SAM_DEPLOY_CMD} --no-fail-on-empty-changeset" +SAM_DEPLOY_CMD="${SAM_DEPLOY_CMD} --parameter-overrides \"ParameterKey=CUSTOM_ROLE_PREFIX,ParameterValue=${CUSTOM_ROLE_PREFIX}\"" +SAM_DEPLOY_CMD="${SAM_DEPLOY_CMD} --s3-prefix \"${LAMBDA_NAME}/\"" +SAM_DEPLOY_CMD="${SAM_DEPLOY_CMD} --no-fail-on-empty-changeset" +# Force upload the artifacts to S3 bucket +# This is useful when the same stack is deployed multiple times via CI/CD pipelines +SAM_DEPLOY_CMD="${SAM_DEPLOY_CMD} --force-upload" +if [ -n "${EXPORTER_SAMCONFIG_FILE}" ]; then + SAM_DEPLOY_CMD="${SAM_DEPLOY_CMD} --config-file \"${EXPORTER_SAMCONFIG_FILE}\"" +fi + +eval "${SAM_DEPLOY_CMD}" \ No newline at end of file From 01851fdf85e954387c37a2f429d5d09b21f0090b Mon Sep 17 00:00:00 2001 From: Stephen Cox Date: Tue, 12 Aug 2025 10:57:54 +1200 Subject: [PATCH 2/3] Added documentation on the config-file option --- docs/reference/aws-deploy-elastic-serverless-forwarder.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/reference/aws-deploy-elastic-serverless-forwarder.md b/docs/reference/aws-deploy-elastic-serverless-forwarder.md index d4fab431..a9664d67 100644 --- a/docs/reference/aws-deploy-elastic-serverless-forwarder.md +++ b/docs/reference/aws-deploy-elastic-serverless-forwarder.md @@ -586,6 +586,7 @@ Usage: ./publish_lambda.sh config-path lambda-name forwarder-tag bucket-name reg region: region where to publish in custom-role-prefix: role/policy prefix to add in case customization is needed (optional) (please note that the prefix will be added to both role/policy naming) + config-file: path to a SAM configuration file (optional) ``` From 2d7a47fe84f6e9f81347b75902e78fc931fc0394 Mon Sep 17 00:00:00 2001 From: Stephen Cox Date: Tue, 12 Aug 2025 11:00:52 +1200 Subject: [PATCH 3/3] Updated change log --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 41ccee84..1c7d3b36 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +### v1.20.2 - 2025/08/12 +##### Docs +* added documentation on a new argumnet to the publish_lambdas.sh +##### Features +* Added a new command line argument to the publish_lambdas.sh to enable use of the --config-file option to support creating tags when deploying sam directly ### v1.20.1 - 2025/05/23 ##### Docs * Fix 404 link in README-AWS.md [903](https://github.com/elastic/elastic-serverless-forwarder/pull/903)