Running APISIX in AWS with AWS CDK

    APISIX is a cloud-native microservices API gateway, delivering the ultimate performance, security, open source and scalable platform for all your APIs and microservices.

    This reference architecture walks you through building APISIX as a serverless container API Gateway on top of AWS Fargate with AWS CDK.

    Generate an AWS CDK project with projen

    update the .projenrc.js with the following content:

    1. const { AwsCdkTypeScriptApp } = require('projen');
    2. const project = new AwsCdkTypeScriptApp({
    3. cdkVersion: "1.70.0",
    4. cdkDependencies: [
    5. '@aws-cdk/aws-ec2',
    6. '@aws-cdk/aws-ecs',
    7. '@aws-cdk/aws-ecs-patterns',
    8. ]
    9. });
    10. project.synth();

    update the project:

    1. $ npx projen

    Deploy the APISIX Stack with AWS CDK

    1. $ cdk diff
    2. $ cdk deploy

    On deployment complete, some outputs will be returned:

    1. Outputs:
    2. apiSix.PhpServiceLoadBalancerDNS5E5BAB1B = apiSi-PhpSe-FOL2MM4TW7G8-09029e095ab36fcc.elb.us-west-2.amazonaws.com
    3. apiSix.ApiSixServiceLoadBalancerDNSD4E5B8CB = apiSi-ApiSi-1TM103DN35GRY-1477666967.us-west-2.elb.amazonaws.com
    4. apiSix.ApiSixServiceServiceURLF6EC7872 = http://apiSi-ApiSi-1TM103DN35GRY-1477666967.us-west-2.elb.amazonaws.com

    All upstream nodes are running as AWS Fargate tasks and registered to the NLB(Network Load Balancer) exposing multiple static IP addresses. We can query the IP addresses by nslookup the apiSix.PhpServiceLoadBalancerDNS5E5BAB1B like this:

    Configure the IP addresses returned as your upstream nodes in your APISIX dashboard followed by the Services and Routes configuration. Let’s say we have a /index.php as the URI for the first route for our first Service from the Upstream IP addresses.

    upstream with AWS NLB IP addresses define route with service and uri

    OK. Let’s test the /index.php on {apiSix.ApiSixServiceServiceURL}/index.php

    Now we have been successfully running APISIX in AWS Fargate as serverless container API Gateway service.

    Clean up

    1. taskDefinition
    2. .addContainer('etcd', {
    3. image: ContainerImage.fromRegistry('gcr.azk8s.cn/etcd-development/etcd:v3.3.12'),
    4. // image: ContainerImage.fromRegistry('gcr.io/etcd-development/etcd:v3.3.12'),
    5. })
    6. .addPortMappings({
    7. containerPort: 2379
    8. })

    (read here for more reference)

    Run cdk deploy and specify your preferred AWS region in China.

    In the following case, we got the Outputs returned for AWS Ningxia region(cn-northwest-1):

    1. Outputs:
    2. apiSix.PhpServiceLoadBalancerDNS5E5BAB1B = apiSi-PhpSe-1760FFS3K7TXH-562fa1f7f642ec24.elb.cn-northwest-1.amazonaws.com.cn
    3. apiSix.ApiSixDashboardURL = http://apiSi-ApiSi-123HOROQKWZKA-1268325233.cn-northwest-1.elb.amazonaws.com.cn/apisix/dashboard/

    Open the apiSix.ApiSixDashboardURL URL and log in to configure your APISIX in AWS China region.

    TBD

    Decouple APISIX and etcd3 on AWS

    For high availability and state consistency consideration, you might be interested to decouple the etcd3 as a separate cluster from APISIX not only for performance but also high availability and fault tolerance yet with highly reliable state consistency.