- vừa được xem lúc

Amazon API Gateway Canary Deployment

0 0 11

Người đăng: AWS Community Builder

Theo Viblo Asia

This pattern creates an Amazon API Gateway RESTful API, an AWS Lambda function, and then creates an APIGW Canary Deployment using the AWS Cloud Development Kit (AWS CDK) in Python.

Learn more about this pattern at Serverless Land Patterns: https://serverlessland.com/patterns/apigw-canary-deployment-cdk.

Important: this application uses various AWS services and there are costs associated with these services after the Free Tier usage - please see the AWS Pricing page for details. You are responsible for any AWS costs incurred. No warranty is implied in this example.

Requirements

Deployment Instructions

  1. Create a new directory, navigate to that directory in a terminal and clone the GitHub repository:

    git clone https://github.com/aws-samples/serverless-patterns
    
  2. Change directory to the pattern directory:

    cd serverless-patterns/apigw-canary-deployment-cdk
    
  3. Create a virtual environment for Python

    python3 -m venv .venv
    
  4. Activate the virtual environment

    source .venv/bin/activate
    

    For a Windows platform, activate the virtualenv like this:

    .venv\Scripts\activate.bat
    
  5. Install the Python required dependencies:

    pip install -r requirements.txt
    
  6. From the command line, use AWS CDK to deploy the AWS resources for the serverless application as specified in the app.py file:

    cdk deploy MyServerlessApplicationStack
    
  7. Note the outputs from the CDK deployment process. These contain the API Gateway ID which is used for testing.

  8. Once the serverless application stack is successfully deployed, you will need to deploy new Lambda code. This can be accomplished by performing the following on the Lambda page in the AWS console:

    1. On the left panel, click functions.
    2. Click on the MyServerlessApplicationStac-MyFunction* function.
    3. Under the code tab, edit the Hello World code under the EDIT ME comment.
    4. Under the file menu in the code editor, click save.
    5. In the code editor, click the deploy button. This deploys the code to the $LATEST version.
  9. From the command line, use AWS CDK to deploy the AWS resources for the canary deployment as specified in the app.py file:

    cdk deploy CanaryDeploymentStack
    

How it works

The API Gateway Canary Deployment will route 50% of the traffic to the new function version created using the updated code.

Testing

From the command line, run the following command to send an HTTP GET request to APIs endpoint. Note that you must edit the {MyServerlessApplicationStack.ApigwId} and {Region} placeholder with the ID of the deployed API and Region that it is deployed in. This is provided in the MyServerlessApplicationStack deployment outputs.

curl -H "Origin: https://www.example.com" "https://{MyServerlessApplicationStack.ApigwId}.execute-api.{Region}.amazonaws.com/prod"

Since the canary deployment is set at 50% traffic, when you run the above command more than once you should see the old version's and new version's output at a rate of about 50/50.

The -H "Origin: https://www.example.com" is the third party domain making the request, which you can substitute for other domains.

Cleanup

  1. Delete the Canary Deployment stack
    cdk destroy CanaryDeploymentStack
    
  2. Delete the Serverless application stack
    cdk destroy MyServerlessApplicationStack
    

Bình luận

Bài viết tương tự

- vừa được xem lúc

PDF Export, cẩn thận với những input có thể truyền vào

Giới thiệu. Dạo gần đây mình tình cờ gặp rất nhiều lỗi XSS, tuy nhiên trang đó lại có sử dụng dữ liệu người dùng input vào để export ra PDF.

0 0 49

- vừa được xem lúc

Giới thiệu về AWS Batch

Khi sử dụng hệ thống cloud service, điều chúng ta thường phải quan tâm đến không chỉ là hiệu suất hoạt động (performance) mà còn phải chú ý đến cả chi phí bỏ ra để duy trì hoạt động của hệ thống. Chắn hẳn là hệ thống lớn hay nhỏ nào cũng đã từng phải dùng đến những instance chuyên để chạy batch thực

0 0 128

- vừa được xem lúc

Tìm hiểu về AWS KMS

1. AWS KMS là gì. Ở KMS bạn có thể lựa chọn tạo symetric key (khóa đối xứng) hoặc asymetric key (khóa bất đối xứng) để làm CMK (Customer Master Key). Sau khi tạo key thì có thể thiết đặt key policy để control quyền access và sử dụng key.

0 0 53

- vừa được xem lúc

AWS VPC cho người mới bắt đầu

Tuần này, tôi trình bày lại những gì tôi đã học được về Virtual Private Cloud (VPC) của Amazon. Nếu bạn muốn xem những gì tôi đã học được về AWS, hãy xem Tổng quan về DynamoDB và Tổng quan về S3. VPC là gì. Những điều cần lưu ý:.

0 0 69

- vừa được xem lúc

AWS Essentials (Phần 6): Guildline SNS Basic trên AWS

Tiếp tục với chuỗi bài viết về Basic AWS Setting, chúng ta tiếp tục tìm hiểu tiếp tới SNS (Simple Notification Service). Đây là một service của AWS cho phép người dùng setting thực hiện gửi email, text message hay push notification tự động tới mobile device dựa trên event người dùng setting phía AWS

0 0 125

- vừa được xem lúc

Sử dụng Amazon CloudFront Content Delivery Network với Private S3 Bucket — Signing URLs

Trong nhiều trường hợp, thì việc sử dụng CDN là bắt buộc. Mình đã trải nghiệm với một số CDN nhưng cuối cùng mình lựa chọn sử dụng AWS CloudFront.

0 0 105