Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
295 views
in Technique[技术] by (71.8m points)

amazon web services - AWS Synthetics Canary script based on the response body

I have created a canaries to test my api. I want to get the result based on the response status "ok". Is that possible to edit the response from canary script. const apiCanaryBlueprint = async function () {

// Handle validation for positive scenario
const validateSuccessfull = async function(res) {
    return new Promise((resolve, reject) => {
        if (res.statusCode < 200 || res.statusCode > 299) {
            throw res.statusCode + ' ' + res.statusMessage;
        }
 
        let responseBody = '';
        let response = '';
        res.on('data', (d) => {
            responseBody = "Success";
            response=+d;
        });
 
        res.on('end', () => {
            // Add validation on 'responseBody' here if required.
            // var JSONObject = JSON.parse(response);
            if(response['floodLocationEligibility']=='Yes')
            {
              responseBody="Eligible"  
            }
            resolve();
        });
    });
};

Output Response Body: {"requestAddress":"330 Elizabeth Rd, San Antonio, TX 78209, USA","location":{"lat":29.4725011,"lon":-98.4534393},"floodLocationEligibility":"Yes","status":"OK"}

Im getting 200 response with above reponse body. I need ony status having "OK". Can anyone suggest me how can i get it. Is that possible to change the script. I attaached the script and response.

question from:https://stackoverflow.com/questions/65917989/aws-synthetics-canary-script-based-on-the-response-body

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...