zoukankan      html  css  js  c++  java
  • [AWS

    1. Create a Lambda function, because we want to work with Application Load Balancer, we need to give a different response from Lambda

    Check: https://docs.aws.amazon.com/lambda/latest/dg/services-alb.html

    exports.handler = async (event) => {
        console.log('event', event);
        // TODO implement
        const response = {
            "statusCode": 200,
            "statusDescription": "200 OK",
            "isBase64Encoded": false,
            "headers": {
                "Content-Type": "text/html"
            },
            "body": "<h1>Hello from Lambda!</h1>"
        };
        return response;
    };

    2. Create "Target Groups", because Lambda must be inside a Target Group in order to work with ALB.

    3. After Target Group becomes `Active`, we can open DNS name in broswer and we should see `Hello from Lambda!` in the page

    4. Enable "Multi-values header" in Target Group

    5. in browser, we can enable url like `http://myalb-labmda-xxxxxx.us-east-1.elb.amazonaws.com/?name=foo&name=bar`

    Noice that it downs the response, but actually we don't want that, we need to modify Lambda response according to:

    https://docs.aws.amazon.com/elasticloadbalancing/latest/application/lambda-functions.html#multi-value-headers-response

    exports.handler = async (event) => {
        console.log('event', event);
        // TODO implement
        const response = {
            "statusCode": 200,
            "statusDescription": "200 OK",
            "isBase64Encoded": false,
            "headers": {
                "Content-Type": "text/html"
            },
            "multiValueHeaders": {
                  "Set-cookie": ["cookie-name=cookie-value;Domain=myweb.com;Secure;HttpOnly","cookie-name=cookie-value;Expires=May 8, 2019"],
                  "Content-Type": ["text/html"]
            },
            "body": "<h1>Hello from Lambda!</h1>"
        };
        return response;
    };

    6. Check from CloudWatch:

    2021-06-03T05:43:17.696Z    5f01fe7f-b7bb-4906-8af7-77579b189a55    INFO    event {
      requestContext: {
        elb: {
          targetGroupArn: 'arn:aws:elasticloadbalancing:us-east-1:xxxxxxxx:targetgroup/myTG-ALB/03b5bf1b78f9e5ac'
        }
      },
      httpMethod: 'GET',
      path: '/',
      multiValueQueryStringParameters: { name: [ 'foo', 'bar' ] },
      multiValueHeaders: {
        accept: [
          'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9'
        ],
        'accept-encoding': [ 'gzip, deflate' ],
        'accept-language': [ 'en-GB,en;q=0.9' ],
    ....
    }, body: '', isBase64Encoded: false }
  • 相关阅读:
    open-falcon之agent
    centos 7 部署 open-falcon 0.2.0
    高可用Redis服务架构分析与搭建
    python操作mongo脚本
    mongo查询日期格式数据
    离线下载pip包安装
    mongo同步到es
    mongo ttl索引
    kibana多台服务部署
    logstash过滤配置
  • 原文地址:https://www.cnblogs.com/Answer1215/p/14844873.html
Copyright © 2011-2022 走看看