From 07c8305a22d1e35bcb02a223704c8bfe5664760f Mon Sep 17 00:00:00 2001 From: Aimee Ukasick Date: Mon, 27 Nov 2023 16:35:13 -0600 Subject: [PATCH 1/2] docs(lambda): Update Get Started for traffic split CDAAS-3074 --- content/en/get-started/lambda/index.md | 131 +++++++++++++++++++++---- 1 file changed, 110 insertions(+), 21 deletions(-) diff --git a/content/en/get-started/lambda/index.md b/content/en/get-started/lambda/index.md index 26ac48bd..31aaaffe 100644 --- a/content/en/get-started/lambda/index.md +++ b/content/en/get-started/lambda/index.md @@ -256,9 +256,7 @@ providerOptions: {{< include "dep-file/lambda-provider-options.md" >}} -## Deploy the sample function - -### First deployment +## Deploy your function Start your deployment using the CLI: @@ -270,7 +268,23 @@ You can use the link provided by the CLI to observe your deployment's progressio {{< figure src="deploy-details.webp" width="80%" height="80%" >}} -### Second deployment +## Test the deployed function + +Go to the `us-east-1` Lamba section of your AWS Account. You should see your deployed `just-sweet-potatoes-dev` function there. + +{{< figure src="deployed-function-list.webp" width="80%" height="80%" >}} + + +1. Click `just-sweet-potatoes-dev` to open the function's details page. +1. Click the **Test** tab. +1. Click the **Test** button in the **Test event** section to test the function. +1. Expand the **Details** section to see the test results. + + {{< figure src="function-test.webp" >}} + +## Update the deployment config file + +### Add target constraints CD-as-a-Service is designed to help you build safety into your app deployment process. It does so by giving you declarative levers to control the scope of your deployment. @@ -281,7 +295,7 @@ CD-as-a-Service has four kinds of constraints that you can use to control your d - [External Automation (Webhooks)]({{< ref "webhooks/overview.md" >}}) to run integration tests and security audits or send notifications - [Automated Canary Analysis]({{< ref "deployment/strategies/canary" >}}) -You can use these constraints between environments and within environments. During your next deployment, you want to issue a manual approval before deploying to to the prod targets. Add to your `staging` target an `afterDeployment` constraint with a manual judgment: +You can use these constraints between environments and within environments. For your next deployment, you are going to add a manual approval before deploying to the prod targets. Add an `afterDeployment` constraint for a manual judgment to your `staging` target: {{< highlight yaml "linenos=table,hl_lines=15-17" >}} targets: @@ -305,7 +319,7 @@ targets: account: deployAsIamRole: region: us-west-1 - strategy: allAtOnce + strategy: trafficSplit constraints: dependsOn: - staging @@ -313,12 +327,101 @@ targets: account: deployAsIamRole: region: us-west-2 - strategy: allAtOnce + strategy: trafficSplit constraints: dependsOn: - staging {{< /highlight>}} +### Add a traffic split canary strategy + +In addition to a manual approval, you're going to add a traffic split strategy to use for the prod targets. The strategy deploys 25%, pauses for manual approval, and then deploys 100%. + +Add to the `strategies` section: + +{{< highlight yaml "linenos=table,hl_lines=7-15" >}} +strategies: + allAtOnce: + canary: + steps: + - setWeight: + weight: 100 + trafficSplit: + canary: + steps: + - setWeight: + weight: 25 + - pause: + untilApproved: true + - setWeight: + weight: 100 +{{< /highlight >}} + +Then update your `targets` section, replacing `allAtOnce` with `trafficSplit` for the prod targets. + +{{< highlight yaml "linenos=table,hl_lines=19 27" >}} +targets: + dev: + account: + deployAsIamRole: + region: us-east-1 + strategy: allAtOnce + staging: + account: + deployAsIamRole: + region: us-east-2 + strategy: allAtOnce + constraints: + dependsOn: + - dev + prod-west-1: + account: + deployAsIamRole: + region: us-west-1 + strategy: trafficSplit + constraints: + dependsOn: + - staging + prod-west-2: + account: + deployAsIamRole: + region: us-west-2 + strategy: trafficSplit + constraints: + dependsOn: + - staging +{{< /highlight >}} + + +#### Create an AWS Lambda alias + +CD-as-a-Service uses an AWS Lambda [alias](https://docs.aws.amazon.com/lambda/latest/dg/configuration-aliases.html) when routing traffic between old and new versions of your function. Before you can use use the `trafficSplit` strategy, create an AWS Lambda alias for the functions you deployed to `prod-west-1` and `prod-west-2`. + +In your AWS Lambda console, make sure you are in region `us-west-1`. Access the details page for `just-sweet-potatoes-prod-west-1`. Open the **Aliases** section, then create an alias with the following values: + +1. **Name**: `live-version` +1. **Version**: `1` + +Repeat for the `just-sweet-potatoes-prod-west-2` function. + +#### Add traffic management info + +Now that you've created aliases, you need to declare those in a new `trafficManagement` section so CD-as-a-Service can perform the traffic split strategy. Add the following top-level section to your deployment config file: + +{{< highlight yaml "linenos=table,hl_lines=19 27" >}} +trafficManagement: + - targets: ['prod-west-1'] + alias: + - function: just-sweet-potatoes-us-west-1 + aliasName: live-version + - targets: ['prod-west-2'] + alias: + - function: just-sweet-potatoes-us-west-2 + aliasName: live-version +{{< /highlight >}} + + +## Deploy your function for a second time Start your second deployment using the CLI: @@ -332,20 +435,6 @@ In this second deployment, you see that CD-as-a-Service paused deployment to pro {{< figure src="manual-constraint.webp" width="80%" height="80%" >}} -## Test the deployed function - -Go to the `us-east-1` Lamba section of your AWS Account. You should see your deployed `just-sweet-potatoes-dev` function there. - -{{< figure src="deployed-function-list.webp" width="80%" height="80%" >}} - - -1. Click `just-sweet-potatoes-dev` to open the function's details page. -1. Click the **Test** tab. -1. Click the **Test** button in the **Test event** section to test the function. -1. Expand the **Details** section to see the test results. - - {{< figure src="function-test.webp" >}} - ## Clean up From 26a71b2b9305450c4595a0c05d10d0aab1d778d2 Mon Sep 17 00:00:00 2001 From: Aimee Ukasick Date: Mon, 27 Nov 2023 16:53:51 -0600 Subject: [PATCH 2/2] add v2 function zip --- .../lambda/files/just-sweet-potatoes-v2.zip | Bin 0 -> 952 bytes content/en/get-started/lambda/index.md | 44 +++++++++++++++++- 2 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 content/en/get-started/lambda/files/just-sweet-potatoes-v2.zip diff --git a/content/en/get-started/lambda/files/just-sweet-potatoes-v2.zip b/content/en/get-started/lambda/files/just-sweet-potatoes-v2.zip new file mode 100644 index 0000000000000000000000000000000000000000..14c7891314f1773357806ec95608656540e3042d GIT binary patch literal 952 zcmWIWW@Zs#0D(JYrQu)(ln`N1V8|*hF3~M6Pfab+EyyoPEXhwT)(;KgWnfp7j7^2% z(h6<{MwYLP3=CkC0>CD6FmNzTKr+#ig@Hi^hl!baDXA5DS;b(JCrZSoasf>T(P$>u z2K#2;b`aS6I-JMy=244fUqmK5aco&W&FNC`iA3GrB}Z4wZrnUc+v|Vz{Szyt?;K-K ze*5Ok?C*-Ae-=-lQhIk+1gl?(x8L%JOHJ;5m7d$>U#2^j)cVf1oV>Wj?xhERPqO~a z)P=XE?pzSG=-Kq&{wo+>RmewN<@)vI=+m-T_K90&$oHS^R^4lzAIsk7n>YRZ?L`}& z-WU3=XZUoQ=EiR~jxL|7pRQxFYKeo?mpH9`3%}1kdn(I%<+9n~PXhj=Ug-Qh;Spz2 zbi`MV>SG)){M$;te(Y+OMipj4xR`M_NT-&cr*R52&Kl7?y+A7tB z&U;<5Zn9bwnr_}xm2>mKhslD8H8*lHN=_DkyTKA+dtcXiOu2 z>bC#EM#(1c<@44y`fPcuuyG^X;WsL-{mH^Az8*V2C+^y?=qqoD+p52Pm%FUCZ% zz0wh~`PC`&HIj$!AJANye0W7o>|w5oP_AvSxsDp~OjYDc%BgVuJKF`o06c zk7T-6P6}vb>b+A?X8pwbw?=!$BJ1);Uqu7AmhiVX_n&*TIWi*c&r1IwUR9xA=E4)U zpL>6C_Er8Bo8pwh()&y_stkX2oG)14EAN~BbgOIlhw5dQRu*mAUO4Uc@9mC-wmaYD zzdGh7n`5h~_Iq34bjC)<&o1S%>hZf)97~yZf_-6!rtlQYscS3y9zN#&u;(vtfHynG zT-yoDq?i~OKq)Q2n~_O`8F#vdrSrFrAQpM49AX13og>>0O6M@Jq%jDG4aBDU0B=?{ RkZDXncm_yc1NxDH0RZqTW=Q}5 literal 0 HcmV?d00001 diff --git a/content/en/get-started/lambda/index.md b/content/en/get-started/lambda/index.md index 31aaaffe..35e215bd 100644 --- a/content/en/get-started/lambda/index.md +++ b/content/en/get-started/lambda/index.md @@ -392,8 +392,45 @@ targets: - staging {{< /highlight >}} +## Upload function v2 -#### Create an AWS Lambda alias +1. Download the function v2 zip file. +1. Rename the zip file to `just-sweet-potatoes.zip`. +1. Upload the file to each of your `armory-demo-lambda-deploy` S3 buckets, overwriting the existing `just-sweet-potatoes.zip` file. + +
Expand to see the v2 code + +```js + +exports.handler = async (event) => { + // Get a random sweet potato fact + const randomFact = potatolessFacts[Math.floor(Math.random() * potatolessFacts.length)]; + + // Prepare the response + const response = { + statusCode: 200, + body: randomFact, + }; + + return response; +}; + +const potatolessFacts = [ + "Sweet potatoes are a great source of vitamin A, which is important for vision health.", + "There are over 400 varieties of sweet potatoes around the world.", + "Sweet potatoes are not related to regular potatoes; they belong to the morning glory family.", + "Sweet potatoes are high in fiber, making them good for digestion.", + "Sweet potatoes come in different colors, including orange, purple, and white.", + "Sweet potatoes are one of the oldest vegetables known to man.", + "North Carolina is the largest producer of sweet potatoes in the United States.", + "Sweet potatoes are often used in Thanksgiving dishes like casseroles and pies.", + "Sweet potatoes and yams are not the same vegetable even though many Americans use the two names interchangeably.", + ]; +``` + +
+ +## Create an AWS Lambda alias CD-as-a-Service uses an AWS Lambda [alias](https://docs.aws.amazon.com/lambda/latest/dg/configuration-aliases.html) when routing traffic between old and new versions of your function. Before you can use use the `trafficSplit` strategy, create an AWS Lambda alias for the functions you deployed to `prod-west-1` and `prod-west-2`. @@ -404,7 +441,7 @@ In your AWS Lambda console, make sure you are in region `us-west-1`. Access the Repeat for the `just-sweet-potatoes-prod-west-2` function. -#### Add traffic management info +## Add traffic management configuration Now that you've created aliases, you need to declare those in a new `trafficManagement` section so CD-as-a-Service can perform the traffic split strategy. Add the following top-level section to your deployment config file: @@ -421,6 +458,9 @@ trafficManagement: {{< /highlight >}} + + + ## Deploy your function for a second time Start your second deployment using the CLI: