Add Lambda rollout with CodeDeploy traffic shifting, smoke tests, and alarm-based rollbacks#6721
Add Lambda rollout with CodeDeploy traffic shifting, smoke tests, and alarm-based rollbacks#6721anatolzak wants to merge 5 commits intoanomalyco:devfrom
Conversation
|
Hey @vimtor! I noticed you recently added the The PR adds full CodeDeploy-managed rollout support to With rollout enabled, In the future, we could also support ECS services through CodeDeploy as well. |
|
thanks for your contribution @anatolzak this looks fantastic, your pull requests are always top tier i'm a bit worried about the scope for this one. the function component it's already very complex i'm wondering what the common use case is here. probably doing a gradual rollout of the new function code? i'm not convinced the other things (sdk, custom alarms or function hooks) i'm not super familiar with codedeploy but my guess is that in 99% of cases people just want to ensure that the new lamba doesn't error what do you think? |
closes #6719
closes #6720
closes #6722
Summary
Adds
rolloutsupport tosst.aws.Functionusing AWS CodeDeploy for controlled traffic shifting on deploy. This enables smoke testing new versions before traffic reaches them, gradual canary/linear deployments, and automatic rollback on CloudWatch alarm triggers.Demos
smoke.test.function.url.mp4
smoke.test.api.gateway.http.api.mp4
smoke.test.router.mp4
smoke.test.lambda.sdk.mp4
canary.deployment.mp4
Changes
New components and SDK
FunctionRolloutcomponent (function-rollout.ts) — encapsulates all CodeDeploy resources (application, deployment group, deployment config, IAM role, deployment, waiter)CodeDeployLambdaDeploymentdynamic provider (codedeploy-lambda-deployment.ts) — creates CodeDeploy deployments via RPCCodeDeployDeploymentWaiterdynamic provider (codedeploy-deployment-waiter.ts) — polls deployment statusrolloutSDK (sdk/js/src/aws/rollout.ts) —rollout.handler()for typed lifecycle hook events,rollout.report()to report status back to CodeDeploy without needing the AWS SDKFunction component changes (
function.ts)rolloutproperty onFunctionArgs— supportsall-at-once,canary, andlinearstrategies with before/after traffic hooks, alarms, SNS notifications, and conflict handlingaddRollout()method — deferred rollout configuration for when hook functions need to reference the parent functionlatestUrl— optional function URL pointing to the latest published version (via alias), separate from the stableurltargetArn/latestTargetArn— getters that resolve to the correct alias ARN for event source subscriptionslatestQualifier— exposed ingetSSTLinkfor invoking the latest version via the Lambda SDKFunctionArgs.transform.rollout(not insiderollout.transform)latestAliasexposed innodesgetterEvent source compatibility
Queue,Bucket,SnsTopic,Dynamo,KinesisStream,ApiGatewayV2,ApiGatewayV1,Realtime,Cron,CognitoUserPool, etc.) now acceptFunctioninstances in their type signatures. By default the components will use the stable alias by using thetargetArn.lambda.Permission— addedqualifierto all permission resources across the codebase, includingssr-site.tsRealtime— migrated fromFunction.fromDefinitiontofunctionBuilder, usestargetArnfor IoT authorizerGo changes
aws-codedeploy.go— shared utilities with struct-based inputs:handleDeploymentConflict,stopDeployment,findActiveDeployment(with pagination),createDeployment,buildAppSpecaws-codedeploy-lambda-deployment.go— Lambda-specific deployment handler that builds AppSpec and manages version diffingExamples
aws-lambda-rollout— full canary rollout with CloudWatch alarms and SNS notificationsaws-lambda-smoke-test— before-traffic hook using Lambda SDK invokeaws-lambda-smoke-test-function-url— before-traffic hook using function URLaws-lambda-smoke-test-http-api— smoke test with API Gateway HTTP APIaws-lambda-smoke-test-router— smoke test with SST RouterTesting locally
The
sst/aws/rolloutSDK is new and not yet published. To test examples locally:Notes
sst dev, the deployed code is a stub that never changes, so rollout is effectively a no-op. Examples setdev: falseto demonstrate this.fn.targetArn. Usingfn.arnbypasses rollout entirely.Note on failed deployments
If a deployment fails (e.g., the before-traffic hook reports failure or an alarm triggers a rollback assuming
wait: true), thesst deployprocess will error out with a message pointing to the CodeDeploy deployment in the AWS console.If you re-run
sst deploywithout changing any function code, the deployment waiter will detect the deployment ID hasn't changed and skip the wait — so the deploy will succeed cleanly without re-triggering the failed deployment. Once you push a code fix and deploy again, a new CodeDeploy deployment is created and validated normally.