@@ -38,24 +38,147 @@ function update_lambda {
3838 if [ 0 -eq $? ]; then
3939 echo " Lambda $LAMBDA_NAME exists"
4040 echo
41- aws lambda update-function-code \
41+ # Update function code and publish a new version
42+ NEW_LAMBDA_VERSION=$( aws lambda update-function-code \
4243 --function-name $LAMBDA_NAME \
4344 --s3-key $LAMBDA_ZIP_FILE \
4445 --s3-bucket $S3_ZIP_FILES \
45- --output text
46+ --publish \
47+ --query ' Version' \
48+ --output text)
49+
50+ echo " New Lambda version created: $NEW_LAMBDA_VERSION "
51+ export NEW_LAMBDA_VERSION
4652 else
4753 echo " Lambda $LAMBDA_NAME does not exist"
4854 fi
4955}
5056
51- function get_lambda_alias_version {
52- version=$( aws lambda get-alias \
57+
58+
59+ function update_core_lambda_alias {
60+ if [ -z " $NEW_LAMBDA_VERSION " ]; then
61+ echo " Error: NEW_LAMBDA_VERSION is not set"
62+ return 1
63+ fi
64+
65+ if [ -z " $CORE_ALIAS_NAME " ]; then
66+ echo " Error: CORE_ALIAS_NAME is not set"
67+ return 1
68+ fi
69+
70+ if [ -z " $LAMBDA_NAME " ]; then
71+ echo " Error: LAMBDA_NAME is not set"
72+ return 1
73+ fi
74+
75+ # Check if alias exists
76+ aws lambda get-alias --function-name $LAMBDA_NAME --name $CORE_ALIAS_NAME > /dev/null 2>&1
77+ if [ 0 -eq $? ]; then
78+ echo " Updating existing Core alias $CORE_ALIAS_NAME to point to version $NEW_LAMBDA_VERSION "
79+ aws lambda update-alias \
80+ --function-name $LAMBDA_NAME \
81+ --name $CORE_ALIAS_NAME \
82+ --function-version $NEW_LAMBDA_VERSION \
83+ --output text
84+ else
85+ echo " Creating new Core alias $CORE_ALIAS_NAME pointing to version $NEW_LAMBDA_VERSION "
86+ aws lambda create-alias \
87+ --function-name $LAMBDA_NAME \
88+ --name $CORE_ALIAS_NAME \
89+ --function-version $NEW_LAMBDA_VERSION \
90+ --output text
91+ fi
92+ }
93+
94+ function update_kfd_lambda_alias {
95+ if [ -z " $NEW_LAMBDA_VERSION " ]; then
96+ echo " Error: NEW_LAMBDA_VERSION is not set"
97+ return 1
98+ fi
99+
100+ if [ -z " $KFD_ALIAS_NAME " ]; then
101+ echo " Error: KFD_ALIAS_NAME is not set"
102+ return 1
103+ fi
104+
105+ if [ -z " $LAMBDA_NAME " ]; then
106+ echo " Error: LAMBDA_NAME is not set"
107+ return 1
108+ fi
109+
110+ # Check if alias exists
111+ aws lambda get-alias --function-name $LAMBDA_NAME --name $KFD_ALIAS_NAME > /dev/null 2>&1
112+ if [ 0 -eq $? ]; then
113+ echo " Updating existing KFD alias $KFD_ALIAS_NAME to point to version $NEW_LAMBDA_VERSION "
114+ aws lambda update-alias \
115+ --function-name $LAMBDA_NAME \
116+ --name $KFD_ALIAS_NAME \
117+ --function-version $NEW_LAMBDA_VERSION \
118+ --output text
119+ else
120+ echo " Creating new KFD alias $KFD_ALIAS_NAME pointing to version $NEW_LAMBDA_VERSION "
121+ aws lambda create-alias \
122+ --function-name $LAMBDA_NAME \
123+ --name $KFD_ALIAS_NAME \
124+ --function-version $NEW_LAMBDA_VERSION \
125+ --output text
126+ fi
127+ }
128+
129+ function get_current_core_lambda_alias {
130+ if [ -z " $CORE_ALIAS_NAME " ]; then
131+ echo " Error: CORE_ALIAS_NAME is not set"
132+ return 1
133+ fi
134+
135+ if [ -z " $LAMBDA_NAME " ]; then
136+ echo " Error: LAMBDA_NAME is not set"
137+ return 1
138+ fi
139+
140+ # Check if alias exists and get current version
141+ CURRENT_CORE_VERSION=$( aws lambda get-alias \
53142 --function-name $LAMBDA_NAME \
54- --name $ALIAS_NAME \
143+ --name $CORE_ALIAS_NAME \
55144 --query ' FunctionVersion' \
56- --output text)
145+ --output text 2> /dev/null)
146+
147+ if [ $? -eq 0 ] && [ " $CURRENT_CORE_VERSION " != " None" ]; then
148+ echo " Current Core alias $CORE_ALIAS_NAME points to version: $CURRENT_CORE_VERSION "
149+ export CURRENT_CORE_ALIAS_VERSION=$CURRENT_CORE_VERSION
150+ else
151+ echo " Core alias $CORE_ALIAS_NAME does not exist or could not be retrieved"
152+ export CURRENT_CORE_ALIAS_VERSION=" "
153+ fi
57154}
58155
156+ function get_current_kfd_lambda_alias {
157+ if [ -z " $KFD_ALIAS_NAME " ]; then
158+ echo " Error: KFD_ALIAS_NAME is not set"
159+ return 1
160+ fi
161+
162+ if [ -z " $LAMBDA_NAME " ]; then
163+ echo " Error: LAMBDA_NAME is not set"
164+ return 1
165+ fi
166+
167+ # Check if alias exists and get current version
168+ CURRENT_KFD_VERSION=$( aws lambda get-alias \
169+ --function-name $LAMBDA_NAME \
170+ --name $KFD_ALIAS_NAME \
171+ --query ' FunctionVersion' \
172+ --output text 2> /dev/null)
173+
174+ if [ $? -eq 0 ] && [ " $CURRENT_KFD_VERSION " != " None" ]; then
175+ echo " Current KFD alias $KFD_ALIAS_NAME points to version: $CURRENT_KFD_VERSION "
176+ export CURRENT_KFD_ALIAS_VERSION=$CURRENT_KFD_VERSION
177+ else
178+ echo " KFD alias $KFD_ALIAS_NAME does not exist or could not be retrieved"
179+ export CURRENT_KFD_ALIAS_VERSION=" "
180+ fi
181+ }
59182
60183function lambda_name {
61184 NAME=` aws ssm get-parameter \
0 commit comments