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 00000000..14c78913 Binary files /dev/null and b/content/en/get-started/lambda/files/just-sweet-potatoes-v2.zip differ diff --git a/content/en/get-started/lambda/index.md b/content/en/get-started/lambda/index.md index 26ac48bd..35e215bd 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,38 +327,153 @@ targets: account: deployAsIamRole: region: us-west-2 - strategy: allAtOnce + strategy: trafficSplit constraints: dependsOn: - staging {{< /highlight>}} +### Add a traffic split canary strategy -Start your second deployment using the CLI: +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%. -```bash -armory deploy start -f deploy.yaml +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 >}} + +## Upload function v2 + +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.", + ]; ``` -Use the link provided by the CLI to observe your deployment's progression in the [CD-as-a-Service Console](https://console.cloud.armory.io/deployments). +
-In this second deployment, you see that CD-as-a-Service paused deployment to prod. Click the **Approve** button in the `staging` node to continue deployment. +## Create an AWS Lambda alias -{{< figure src="manual-constraint.webp" width="80%" height="80%" >}} +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`. -## Test the deployed function +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: -Go to the `us-east-1` Lamba section of your AWS Account. You should see your deployed `just-sweet-potatoes-dev` function there. +1. **Name**: `live-version` +1. **Version**: `1` -{{< figure src="deployed-function-list.webp" width="80%" height="80%" >}} +Repeat for the `just-sweet-potatoes-prod-west-2` function. +## Add traffic management configuration -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. +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: - {{< figure src="function-test.webp" >}} +{{< 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: + +```bash +armory deploy start -f deploy.yaml +``` + +Use the link provided by the CLI to observe your deployment's progression in the [CD-as-a-Service Console](https://console.cloud.armory.io/deployments). + +In this second deployment, you see that CD-as-a-Service paused deployment to prod. Click the **Approve** button in the `staging` node to continue deployment. + +{{< figure src="manual-constraint.webp" width="80%" height="80%" >}} ## Clean up