首页 > 解决方案 > 准备好的代码上的 AWS Elasticache Redis 未在 lambda 中执行

问题描述

这是我写的 lambda

"use strict";

const redis = require('redis');

exports.handler = async (event, context, callback) => {
    const client = redis.createClient({url: 'redis://anaha-redis.something.so.0001.meth.ing.amazonaws.com:6379'});

    client.on("error", (err) => {
        client.quit();
        console.log("Redis encountered an error.");
        callback(err, null);
    });
    
    client.on("ready", () => {
        const data = { type: "helloWorld", data: "Hello World!" };
        client.publish("testLambda-get-test-helloWorld", JSON.stringify(data));
        client.quit();
        console.log("HELLLLLOOOOOOOOOOOOOOO",data);
        return data;
    });
};

但是里面的代码准备就绪并没有被执行。因为 Cloud Watch Logs 没有显示 HELLLLLOOOOOOOOOOOOOOO,因为我已经登录了那部分代码。

我究竟做错了什么?什么是更好的方法?

标签: amazon-web-servicesredisaws-lambdaamazon-elasticache

解决方案


推荐阅读