API  deployment  -Release options 
Published: 2021-07-18 07:39:53

Application frequently deploy updates to introduce new features in their stack. But updating the production is risky and may introduce bugs .Canary / blue green deployments help to mitigate the risk.

Design a release strategy to  partially deploy  a new  feature and shift some percentage of traffic to a new version of the application. This allows  to verify stability and reduce risk associated with the new release. After gaining confidence in the new version,  continually increment traffic until all traffic flows to the new release. 

Multiple options are available to partially deploy  a new  feature and shift some percentage of traffic to a new version of the application.


![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/foms1yaef4lceavrn3h2.png)
 



**Option1: Lambda Weighted Alias Routing** 

      1.Create two different versions of lambda functions

      2.Create Alias with routing config and 
        additional weights to route the traffic  



Prodversion:
  Type: AWS::Lambda::Version
  Properties:
    FunctionName: !Ref function
    Description: v1
Stageversion:
  Type: AWS::Lambda::Version
  Properties:
    FunctionName: !Ref function
    Description: v2
alias:
  Type: AWS::Lambda::Alias
  Properties:
    FunctionName: !Ref function
    FunctionVersion: !GetAtt ProdVersion.Version
    Name: BLUE
    RoutingConfig:
      AdditionalVersionWeights:
        - FunctionVersion: !GetAtt Stageversion.Version
          FunctionWeight: 0.5

Update the alias to modify the routing 

          aws lambda update-alias --name routing-alias --function-name $function  \
          --function-version 1 --routing-config AdditionalVersionWeights={}
          
          aws lambda update-alias --name routing-alias --function-name $function  \
          --function-version 2 --routing-config AdditionalVersionWeights={}
 




![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lvl6g7rvfmwm83df2s7h.png)
 



**Option2:Route based Lambda Alias** 


       1.Create 2 different function versions and aliases 
          lamda-function:stage ,lamda-function:prod

       2. Create dynamic resources in AWS API gateway 
          (API – Call lambda with aliases)
          Integration Request Lambda function name: 
          lambda-function:${stageVariables.env}

       3. Create deployment stages and variables in 
          API gateway -  Prod deployment Stage , 
          Staging  deployment stage
 



![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ho60w2jchyduxfuhmnhe.png)
 
 


 **Option3: Release using Code deploy and SAM template – Pre and Post traffic hook Lambdas**


    1.Use SAM based deployment.

    2.Include code deploy and lambda weighted Alias. 

    3.Pre and post traffic lambda functions to include 
      test scenarios.

    4.Cloud watch to monitor the health and to rollback 
      deployment based on the lambda execution error alerts




![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y0uf4w5hj4usty8bvlf4.png)





**Option 4: API Based Route**
   
   
    1.Create baseline deployment with two stage 
      variables [Prod ,Stage].
    2.Create canary deployment on the prod stage to 
      create API test version including traffic 
      split between prod and test API version.
    3.Promote the Canary to reset the canary 
      percentage to Zero.




![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f6r9cor5img05c6atb0c.png)