异步Lambda函数:返回promise或发送responseURL不会终止CloudFormation定制资源调用 [英] Async Lambda Function: Returning promise or sending responseURL does not terminate CloudFormation custom resource invocation

查看:90
本文介绍了异步Lambda函数:返回promise或发送responseURL不会终止CloudFormation定制资源调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个lambda函数通过CloudFormation模板作为自定义资源被调用.它创建/删除AWS Connect实例.API调用工作正常,但我似乎无法终止自定义资源调用,因此最后一个CF块仍为CREATE_IN_PROGRESS.无论我从异步函数返回什么,它都不会成功终止CF执行.

我能够像

位于 https://docs.aws的文档.amazon.com/lambda/latest/dg/nodejs-handler.html 明确指出,您应该可以直接从任何异步函数中直接返回等待apiCall.promise()正在尝试做,例如

  const s3 =新的AWS.S3()exports.handler =异步函数(事件){返回s3.listBuckets().promise()} 

为什么我不能从异步函数返回?API调用再次正常工作,创建并删除了Connect实例(尽管为简洁起见,我省略了删除代码),但是CF只是挂了几个小时,直到最终说自定义资源未能在预期的时间内稳定下来".

为便于阅读,以下是内联代码:

  exports.handler =异步函数(事件){console.log(收到请求:\ n" + JSON.stringify(event));var connect = new aws.Connect({region:event.ResourceProperties.Region});var isInboundCallsEnabled =(process.env.InboundCallsEnabled =='true');var isOutboundCallsEnabled =(process.env.OutboundCallsEnabled =='true');var createInstanceParams = {InboundCallsEnabled:isInboundCallsEnabled,OutboundCallsEnabled:isOutboundCallsEnabled,IdentityManagementType:process.env.IdentityManagementType,ClientToken:process.env.ClientToken,DirectoryId:process.env.DirectoryId,InstanceAlias:process.env.InstanceAlias};//使用指定的参数创建AWS Connect实例如果(event.RequestType ==创建"){返回等待connect.createInstance(createInstanceParams).promise();//我可以将其存储在变量中,并且可以正常读取内容,但是...//返回承诺不会终止CF执行}}; 

更新:我已经完全按照AMI查找示例(第一个链接)中所示的方式实现了sendResponse方法,并且正在为响应发送完全正确的结构,它甚至在数据字段中包括新创建的连接实例ID:

  {状态":成功",原因":查看CloudWatch Log Stream中的详细信息:2020/12/23/[$ LATEST] 6fef35538​​70b4fba90479a37b4360cee","PhysicalResourceId":"2020/12/23/[$ LATEST] 6fef35538​​70b4fba90479a37b4360cee","StackId":"arn:aws:cloudformation:us-east-1:642608065726:stack/cr12/1105a290-4534-11eb-a6de-0a8534d05dcd","RequestId":"2f7c3d9e-941f-402c-b739-d2d965288cfe","LogicalResourceId":"InvokeCreateConnectInstance",数据":{"InstanceId":"2ca7aa49-9b20-4feb-8073-5f23d63e4cbc"}} 

并且仍然在CloudFormation中仅关闭自定义资源.当我将以上内容返回给event.responseURL时,我只是不明白为什么会发生这种情况.就像指定异步处理程序会完全破坏自定义资源处理程序并阻止其关闭一样.

更新:当我手动将上面的响应直接CURL到event.responseUrl时,CF资源注册成功!WTF ...我发送的响应与lambda函数发送的响应完全相同,并且它从CURL接受但不是从我的lambda函数接受.

更新:最新代码,包括sendResponse等

  var aws = require("aws-sdk");exports.handler =异步函数(事件,上下文,回调){console.log(收到请求:\ n" + JSON.stringify(event));var connect = new aws.Connect({region:event.ResourceProperties.Region});var isInboundCallsEnabled =(process.env.InboundCallsEnabled =='true');var isOutboundCallsEnabled =(process.env.OutboundCallsEnabled =='true');var createInstanceParams = {InboundCallsEnabled:isInboundCallsEnabled,OutboundCallsEnabled:isOutboundCallsEnabled,IdentityManagementType:process.env.IdentityManagementType,ClientToken:process.env.ClientToken,DirectoryId:process.env.DirectoryId,InstanceAlias:process.env.InstanceAlias};var responseStatus;var responseData = {};//创建Connect实例如果(event.RequestType ==创建"){尝试 {var createInstanceRequest =等待connect.createInstance(createInstanceParams).promise();responseStatus =成功";responseData = {"InstanceId":createInstanceRequest.Id};} catch(err){responseStatus =失败";responseData = {错误:"CreateInstance失败"''};console.log(responseData.Error +:\ n",err);}sendResponse(事件,上下文,responseStatus,responseData);返回;}//查找ID,然后调用deleteInstance.如果(event.RequestType ==删除"){var instanceId;var listInstanceRequest =等待connect.listInstances({}).promise();listInstanceRequest.InstanceSummaryList.forEach(instance => {如果(instance.InstanceAlias == createInstanceParams.InstanceAlias){instanceId = instance.Id;}});如果(instanceId!==未定义){尝试 {var deleteInstanceRequest =等待connect.deleteInstance({"InstanceId":instanceId}).promise();responseStatus =成功";responseData = {"InstanceId":instanceId};} catch(err){responseStatus =失败";responseData = {错误:"DeleteInstance调用失败"}};console.log(responseData.Error +:\ n",err);}} 别的 {responseStatus =失败";responseData = {错误:"DeleteInstance失败;找不到匹配项"}};console.log(responseData.Error);}sendResponse(事件,上下文,responseStatus,responseData);返回;}};//将响应发送到预先签名的S3 URL函数sendResponse(事件,上下文,responseStatus,responseData){var responseBody = JSON.stringify({状态:responseStatus,原因:"CloudWatch Log Stream:"+ context.logStreamName,PhysicalResourceId:context.logStreamName,StackId:event.StackId,RequestId:event.RequestId,LogicalResourceId:event.LogicalResourceId,数据:responseData});console.log("RESPONSE BODY:\ n",responseBody);var https = require("https");var url = require("url");var parsedUrl = url.parse(event.ResponseURL);var options = {主机名:parsedUrl.hostname,端口:443,路径:parsedUrl.path,方法:"PUT",标头:{"content-type":","content-length":responseBody.length}};console.log(发送响应... \ n");var request = https.request(options,function(response){console.log(状态:" + response.statusCode);console.log("HEADERS:" + JSON.stringify(response.headers));//告诉AWS Lambda函数执行已完成context.done();});request.on("error",function(error){console.log("sendResponse错误:" +错误);//告诉AWS Lambda函数执行已完成context.done();});//将数据写入请求主体request.write(responseBody);request.end();} 

现在已经呆了两天了:(

在日志中的

PS中,"RESPONSE BODY"就像我上面复制的那样,按预期方式显示,日志显示"SENDING RESPONSE"但不会进入状态:"和"HEADERS:"request.https()调用的一部分,这使我认为异步操作会干扰此调用... IDK

解决方案

这确实很棘手,但最终一切都搞定了.我必须通过向其添加一个承诺,等待该承诺并返回它来使sendResponse函数异步.这使我最终可以调用返回等待sendResponse(事件,上下文,responseStatus,responseData);".最后一切正常,创建和删除操作均成功,并且CloudFormation自定义资源按预期完成.ew希望在这里发布代码,希望其他人能从中受益.

  var aws = require("aws-sdk");exports.handler =异步函数(事件,上下文,回调){console.log(收到请求:\ n" + JSON.stringify(event));var connect = new aws.Connect({region:event.ResourceProperties.Region});var isInboundCallsEnabled =(process.env.InboundCallsEnabled =='true');var isOutboundCallsEnabled =(process.env.OutboundCallsEnabled =='true');var createInstanceParams = {InboundCallsEnabled:isInboundCallsEnabled,OutboundCallsEnabled:isOutboundCallsEnabled,IdentityManagementType:process.env.IdentityManagementType,ClientToken:process.env.ClientToken,DirectoryId:process.env.DirectoryId,InstanceAlias:process.env.InstanceAlias};var responseStatus;var responseData = {};如果(event.RequestType ==创建"){尝试 {var createInstanceRequest =等待connect.createInstance(createInstanceParams).promise();responseStatus =成功";responseData = {"InstanceId":createInstanceRequest.Id};} catch(err){responseStatus =失败";responseData = {错误:"CreateInstance失败"''};console.log(responseData.Error +:\ n",err);}返回等待sendResponse(事件,上下文,responseStatus,responseData);}如果(event.RequestType ==删除"){var instanceId;var listInstanceRequest =等待connect.listInstances({}).promise();listInstanceRequest.InstanceSummaryList.forEach(instance => {如果(instance.InstanceAlias == createInstanceParams.InstanceAlias){instanceId = instance.Id;}});如果(instanceId!==未定义){尝试 {var deleteInstanceRequest =等待connect.deleteInstance({"InstanceId":instanceId}).promise();responseStatus =成功";responseData = {"InstanceId":instanceId};} catch(err){responseStatus =失败";responseData = {错误:"DeleteInstance调用失败"}};console.log(responseData.Error +:\ n",err);}} 别的 {responseStatus =失败";responseData = {错误:"DeleteInstance失败;找不到匹配项"}};console.log(responseData.Error);}返回等待sendResponse(事件,上下文,responseStatus,responseData);}};异步函数sendResponse(事件,上下文,responseStatus,responseData){让responsePromise =新的Promise((resolve,reject)=> {var responseBody = JSON.stringify({状态:responseStatus,原因:"CloudWatch Log Stream:"+ context.logStreamName,PhysicalResourceId:context.logStreamName,StackId:event.StackId,RequestId:event.RequestId,LogicalResourceId:event.LogicalResourceId,数据:responseData});console.log("RESPONSE BODY:\ n",responseBody);var https = require("https");var url = require("url");var parsedUrl = url.parse(event.ResponseURL);var options = {主机名:parsedUrl.hostname,端口:443,路径:parsedUrl.path,方法:"PUT",标头:{"content-type":","content-length":responseBody.length}};console.log(发送响应... \ n");var request = https.request(options,function(response){console.log(状态:" + response.statusCode);console.log("HEADERS:" + JSON.stringify(response.headers));resolve(JSON.parse(responseBody));context.done();});request.on("error",function(error){console.log("sendResponse错误:" +错误);拒绝(错误);context.done();});request.write(responseBody);request.end();});返回等待responsePromise;} 

I have a lambda function invoked as a custom resource via a CloudFormation template. It Creates/Deletes AWS Connect instances. The API calls work fine but I cannot seem to terminate the custom resource invocation, so the last CF block remains CREATE_IN_PROGRESS. No matter what I return from the async function it just won't terminate the CF execution with a success.

I'm able to use a non-async handler successfully as in https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/walkthrough-custom-resources-lambda-lookup-amiids.html but I need to make multiple API calls and await completions, hence the need for async handler.

Below is the code in it's simplest form, though I've tried just about everything, including using callback and context (ie exports.handler = async function(event, context, callback) {...}), both of which should be unnecessary with an async handler. I've tried using cfn-response to directly send a response which seems to be ignored with async handlers. I've tried returning directly the promises with and without the await before them, tried returning variables containing various responseStatus and responseData, nothing seems to work.

Transform: 'AWS::Serverless-2016-10-31'
Parameters:
  IdentityManagementType:
    Description: The type of identity management for your Amazon Connect users.
    Type: String
    AllowedValues: ["SAML", "CONNECT_MANAGED", "EXISTING_DIRECTORY"]
    Default: "SAML"
  InboundCallsEnabled:
    Description: Whether your contact center handles incoming contacts.
    Type: String
    AllowedValues: [true, false]
    Default: true
  InstanceAlias:
    Description: The name for your instance.
    Type: String
    MaxLength: 62
  OutboundCallsEnabled:
    Description: Whether your contact center allows outbound calls.
    Type: String
    AllowedValues: [true, false]
    Default: true
  DirectoryId:
    Description: Optional. The identifier for the directory, if using this type of Identity Management.
    Type: String
  ClientToken:
    Description: Optional. The idempotency token. Used for concurrent deployments
    Type: String
    MaxLength: 500
  Region:
    Description: Region to place the AWS Connect Instance
    Type: String
    Default: us-east-1
#Handler for optional values
Conditions:
  HasClientToken: !Not
    - !Equals
      - ""
      - !Ref ClientToken
  HasDirectoryId: !Not
    - !Equals
      - ""
      - !Ref DirectoryId

Resources:
  CreateConnectInstance:
    Type: AWS::Serverless::Function
    Properties:
      FunctionName: !Sub "${AWS::StackName}-AWSConnectInstance"
      Handler: index.handler
      Runtime: nodejs12.x
      Description: Invoke a function to create an AWS Connect instance.
      MemorySize: 128
      Timeout: 30
      Role: !GetAtt LambdaExecutionRole.Arn
      Layers:
        - !Sub "arn:aws:lambda:us-east-1:${AWS::AccountId}:layer:node_sdk:1"
      Environment:
        Variables:
          IdentityManagementType:
            Ref: IdentityManagementType
          InboundCallsEnabled:
            Ref: InboundCallsEnabled
          InstanceAlias:
            Ref: InstanceAlias
          OutboundCallsEnabled:
            Ref: OutboundCallsEnabled
          Region:
            Ref: Region
          #Optional Values
          ClientToken: !If
            - HasClientToken
            - !Ref ClientToken
            - !Ref "AWS::NoValue"
          DirectoryId: !If
            - HasClientToken
            - !Ref ClientToken
            - !Ref "AWS::NoValue"
      InlineCode: |
        var aws = require("aws-sdk");
        exports.handler = async function(event) {
            console.log("REQUEST RECEIVED:\n" + JSON.stringify(event));
            var connect = new aws.Connect({region: event.ResourceProperties.Region});
            var isInboundCallsEnabled = (process.env.InboundCallsEnabled == 'true');
            var isOutboundCallsEnabled = (process.env.OutboundCallsEnabled == 'true');
            var createInstanceParams = {
                InboundCallsEnabled: isInboundCallsEnabled,
                OutboundCallsEnabled: isOutboundCallsEnabled,
                IdentityManagementType: process.env.IdentityManagementType,
                ClientToken: process.env.ClientToken,
                DirectoryId: process.env.DirectoryId,
                InstanceAlias: process.env.InstanceAlias
            };

            // Create AWS Connect instance using specified parameters
            if (event.RequestType == "Create") {
                return await connect.createInstance(createInstanceParams).promise();
                // I can store this in a variable and read the contents fine, but...
                // returning the promise does not terminate execution
            }
        };


  InvokeCreateConnectInstance:
    Type: Custom::CreateConnectInstance
    Properties:
      ServiceToken: !GetAtt CreateConnectInstance.Arn
      Region: !Ref "AWS::Region"

The documentaiton at https://docs.aws.amazon.com/lambda/latest/dg/nodejs-handler.html explicitly states that you should be able to return await apiCall.promise() directly from any async function, exactly what I'm trying to do, such as

const s3 = new AWS.S3()

exports.handler = async function(event) {
  return s3.listBuckets().promise()
}

Why can't I return from my async function? Again the API calls are working, the Connect instances are created and deleted (though I've omitted the delete code for brevity), but CF just hangs hours and hours until eventually saying "Custom Resource failed to stabilize in expected time"

Here's the inline code by itself for readability:

        exports.handler = async function(event) {
            console.log("REQUEST RECEIVED:\n" + JSON.stringify(event));
            var connect = new aws.Connect({region: event.ResourceProperties.Region});
            var isInboundCallsEnabled = (process.env.InboundCallsEnabled == 'true');
            var isOutboundCallsEnabled = (process.env.OutboundCallsEnabled == 'true');
            var createInstanceParams = {
                InboundCallsEnabled: isInboundCallsEnabled,
                OutboundCallsEnabled: isOutboundCallsEnabled,
                IdentityManagementType: process.env.IdentityManagementType,
                ClientToken: process.env.ClientToken,
                DirectoryId: process.env.DirectoryId,
                InstanceAlias: process.env.InstanceAlias
            };

            // Create AWS Connect instance using specified parameters
            if (event.RequestType == "Create") {
                return await connect.createInstance(createInstanceParams).promise();
                // I can store this in a variable and read the contents fine, but...
                // returning the promise does not terminate CF execution
            }
          };

UPDATE: I've implemented the sendResponse method exactly as shown in the AMI lookup example (the first link) and am sending exactly the correct structure for the response, it even includes the newly created connect instance ID in the data field:

{
    "Status": "SUCCESS",
    "Reason": "See the details in CloudWatch Log Stream: 2020/12/23/[$LATEST]6fef3553870b4fba90479a37b4360cee",
    "PhysicalResourceId": "2020/12/23/[$LATEST]6fef3553870b4fba90479a37b4360cee",
    "StackId": "arn:aws:cloudformation:us-east-1:642608065726:stack/cr12/1105a290-4534-11eb-a6de-0a8534d05dcd",
    "RequestId": "2f7c3d9e-941f-402c-b739-d2d965288cfe",
    "LogicalResourceId": "InvokeCreateConnectInstance",
    "Data": {
        "InstanceId": "2ca7aa49-9b20-4feb-8073-5f23d63e4cbc"
    }
}

And STILL the custom resource will just not close in CloudFormation. I just don't understand why this is happening when I am returning the above to the event.responseURL. It's like specifying an async handler completely breaks the custom resource handler and prevents it from closing.

UPDATE: When I manually CURL the above response directly to the event.responseUrl the CF resource registers a success! WTF... I'm sending the exact same response as the lambda function is sending, and it accepts it from the CURL but not from my lambda function.

UPDATE: latest code including sendResponse, etc

var aws = require("aws-sdk");
exports.handler = async function(event, context, callback) {
    console.log("REQUEST RECEIVED:\n" + JSON.stringify(event));
    var connect = new aws.Connect({region: event.ResourceProperties.Region});
    var isInboundCallsEnabled = (process.env.InboundCallsEnabled == 'true');
    var isOutboundCallsEnabled = (process.env.OutboundCallsEnabled == 'true');
    var createInstanceParams = {
        InboundCallsEnabled: isInboundCallsEnabled,
        OutboundCallsEnabled: isOutboundCallsEnabled,
        IdentityManagementType: process.env.IdentityManagementType,
        ClientToken: process.env.ClientToken,
        DirectoryId: process.env.DirectoryId,
        InstanceAlias: process.env.InstanceAlias
    };
    var responseStatus;
    var responseData = {};

    // Create Connect instance
    if (event.RequestType == "Create") {
        try {
            var createInstanceRequest = await connect.createInstance(createInstanceParams).promise();
            responseStatus = "SUCCESS";
            responseData = {"InstanceId": createInstanceRequest.Id};
        } catch (err) {
            responseStatus = "FAILED";
            responseData = {Error: "CreateInstance failed"};
            console.log(responseData.Error + ":\n", err);
        }
        sendResponse(event, context, responseStatus, responseData);
        return;
    }

    // Look up the ID and call deleteInstance.
    if (event.RequestType == "Delete") {
        var instanceId;
        var listInstanceRequest = await connect.listInstances({}).promise();
        listInstanceRequest.InstanceSummaryList.forEach(instance => {
            if (instance.InstanceAlias == createInstanceParams.InstanceAlias) {
                instanceId = instance.Id;
            }
        });
        if (instanceId !== undefined) {
            try {
                var deleteInstanceRequest = await connect.deleteInstance({"InstanceId": instanceId}).promise();
                responseStatus = "SUCCESS";
                responseData = {"InstanceId": instanceId};
            } catch (err) {
                responseStatus = "FAILED";
                responseData = {Error: "DeleteInstance call failed"};
                console.log(responseData.Error + ":\n", err);
            }
        } else {
            responseStatus = "FAILED";
            responseData = {Error: "DeleteInstance failed; no match found"};
            console.log(responseData.Error);
        }
        sendResponse(event, context, responseStatus, responseData);
        return;
    }
};

// Send response to the pre-signed S3 URL 
function sendResponse(event, context, responseStatus, responseData) {
    var responseBody = JSON.stringify({
        Status: responseStatus,
        Reason: "CloudWatch Log Stream: " + context.logStreamName,
        PhysicalResourceId: context.logStreamName,
        StackId: event.StackId,
        RequestId: event.RequestId,
        LogicalResourceId: event.LogicalResourceId,
        Data: responseData
    });
    console.log("RESPONSE BODY:\n", responseBody);
    var https = require("https");
    var url = require("url");
    var parsedUrl = url.parse(event.ResponseURL);
    var options = {
        hostname: parsedUrl.hostname,
        port: 443,
        path: parsedUrl.path,
        method: "PUT",
        headers: {
            "content-type": "",
            "content-length": responseBody.length
        }
    };
    console.log("SENDING RESPONSE...\n");
    var request = https.request(options, function(response) {
        console.log("STATUS: " + response.statusCode);
        console.log("HEADERS: " + JSON.stringify(response.headers));
        // Tell AWS Lambda that the function execution is done  
        context.done();
    });
    request.on("error", function(error) {
        console.log("sendResponse Error:" + error);
        // Tell AWS Lambda that the function execution is done  
        context.done();
    });
    // write data to request body
    request.write(responseBody);
    request.end();
}

Been at this for two days now :(

PS in the logs the "RESPONSE BODY" is shown as expected like I copied above, and log shows the "SENDING RESPONSE" but does not get to the the "STATUS: " and "HEADERS: " portion of the request.https() call, which makes me think something with async interferes with this call... IDK

解决方案

This one was really tricky but finally have everything figured out. I had to make the sendResponse function asynchronous by adding a promise to it, awaiting that promise and returning it. This allowed me to ultimately call "return await sendResponse(event, context, responseStatus, responseData);" and finally everything is working, both create and delete operations are successful and the CloudFormation custom resource completes as expected. Phew. Posting code here in hopes that others will benefit from it.

var aws = require("aws-sdk");
exports.handler = async function(event, context, callback) {
    console.log("REQUEST RECEIVED:\n" + JSON.stringify(event));
    var connect = new aws.Connect({region: event.ResourceProperties.Region});
    var isInboundCallsEnabled = (process.env.InboundCallsEnabled == 'true');
    var isOutboundCallsEnabled = (process.env.OutboundCallsEnabled == 'true');
    var createInstanceParams = {
        InboundCallsEnabled: isInboundCallsEnabled,
        OutboundCallsEnabled: isOutboundCallsEnabled,
        IdentityManagementType: process.env.IdentityManagementType,
        ClientToken: process.env.ClientToken,
        DirectoryId: process.env.DirectoryId,
        InstanceAlias: process.env.InstanceAlias
    };
    var responseStatus;
    var responseData = {};
    if (event.RequestType == "Create") {
        try {
            var createInstanceRequest = await connect.createInstance(createInstanceParams).promise();
            responseStatus = "SUCCESS";
            responseData = {"InstanceId": createInstanceRequest.Id};
        } catch (err) {
            responseStatus = "FAILED";
            responseData = {Error: "CreateInstance failed"};
            console.log(responseData.Error + ":\n", err);
        }
        return await sendResponse(event, context, responseStatus, responseData);
    }

    if (event.RequestType == "Delete") {
        var instanceId;
        var listInstanceRequest = await connect.listInstances({}).promise();
        listInstanceRequest.InstanceSummaryList.forEach(instance => {
            if (instance.InstanceAlias == createInstanceParams.InstanceAlias) {
                instanceId = instance.Id;
            }
        });
        if (instanceId !== undefined) {
            try {
                var deleteInstanceRequest = await connect.deleteInstance({"InstanceId": instanceId}).promise();
                responseStatus = "SUCCESS";
                responseData = {"InstanceId": instanceId};
            } catch (err) {
                responseStatus = "FAILED";
                responseData = {Error: "DeleteInstance call failed"};
                console.log(responseData.Error + ":\n", err);
            }
        } else {
            responseStatus = "FAILED";
            responseData = {Error: "DeleteInstance failed; no match found"};
            console.log(responseData.Error);
        }
        return await sendResponse(event, context, responseStatus, responseData);
    }
};

async function sendResponse(event, context, responseStatus, responseData) {
    let responsePromise = new Promise((resolve, reject) => {
        var responseBody = JSON.stringify({
            Status: responseStatus,
            Reason: "CloudWatch Log Stream: " + context.logStreamName,
            PhysicalResourceId: context.logStreamName,
            StackId: event.StackId,
            RequestId: event.RequestId,
            LogicalResourceId: event.LogicalResourceId,
            Data: responseData
        });
        console.log("RESPONSE BODY:\n", responseBody);
        var https = require("https");
        var url = require("url");
        var parsedUrl = url.parse(event.ResponseURL);
        var options = {
            hostname: parsedUrl.hostname,
            port: 443,
            path: parsedUrl.path,
            method: "PUT",
            headers: {
                "content-type": "",
                "content-length": responseBody.length
            }
        };
        console.log("SENDING RESPONSE...\n");
        var request = https.request(options, function(response) {
            console.log("STATUS: " + response.statusCode);
            console.log("HEADERS: " + JSON.stringify(response.headers));
            resolve(JSON.parse(responseBody));
            context.done();
        });
        request.on("error", function(error) {
            console.log("sendResponse Error:" + error);
            reject(error);
            context.done();
        });
        request.write(responseBody);
        request.end();
    });
    return await responsePromise;
}

这篇关于异步Lambda函数:返回promise或发送responseURL不会终止CloudFormation定制资源调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆