From 213b5bb4fd00f757f5c947a9c05b74c873e3dced Mon Sep 17 00:00:00 2001 From: Gideon Goldberg <1764158+gidsg@users.noreply.github.com> Date: Mon, 23 Dec 2024 16:16:56 +0000 Subject: [PATCH] try interpolating username --- .../addons/basic-auth-cloudfront-function.yml | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/apps/pre-award/copilot/environments/addons/basic-auth-cloudfront-function.yml b/apps/pre-award/copilot/environments/addons/basic-auth-cloudfront-function.yml index 45359fb..8d82326 100644 --- a/apps/pre-award/copilot/environments/addons/basic-auth-cloudfront-function.yml +++ b/apps/pre-award/copilot/environments/addons/basic-auth-cloudfront-function.yml @@ -11,19 +11,21 @@ Resources: Properties: Name: EnforceBasicAuth FunctionConfig: - Comment: A basic CloudFront function + Comment: A CloudFront function to enforce basic auth Runtime: cloudfront-js-2.0 - FunctionCode: | - function handler(event) { - // NOTE: This example function is for a viewer request event trigger. - // Choose viewer request for the event trigger when you associate this function with a distribution. - var response = { - statusCode: 200, - statusDescription: 'OK', - headers: { - 'cloudfront-functions': { value: 'generated-by-CloudFront-Functions' } - } - }; - return response; - } + FunctionCode: + !Sub | + function handler(event) { + const username = ${AWS::NoValue}${!SSM[/copilot/${App}/${Env}/secrets/BASIC_AUTH_USERNAME} + // NOTE: This example function is for a viewer request event trigger. + // Choose viewer request for the event trigger when you associate this function with a distribution. + var response = { + statusCode: 200, + statusDescription: 'OK', + headers: { + 'cloudfront-functions': { value: 'generated-by-CloudFront-Functions' } + } + }; + return response; + } AutoPublish: false \ No newline at end of file