首页 > 解决方案 > 调用 AWS Lambda 端点

问题描述

我实现了 AWS lambda 方法来了解我可以用它做什么。我现在拥有的:

在 API Gateway 配置中,我看到了下一个选项:

在这个 lambda 后面我有 Java 代码,实现com.amazonaws.services.lambda.runtime.RequestStreamHandler和它背后的 REST 控制器,类似这样:

@Path("/tester")
public class TestResource {

    private static final Logger LOG = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());

    private TestRepository testRepository;

    public void setTestRepository(TestRepository testRepository) {
        this.testRepository = testRepository;
    }

    @POST
    @Path("/{identifier}")
    @Produces(MediaType.TEXT_PLAIN)
    @Consumes(MediaType.WILDCARD)
    public Response store(@PathParam("identifier") String identifier, @QueryParam("hashcode") String hashcode) {
        try {
            this.testRepository.store(identifier, hashcode);
        } catch (RuntimeException ex) {
            LOG.error("Failed to store pair {}, {}", identifier, hashcode, ex);
            throw new InternalServerErrorException(ex);
        }
        return Response.noContent().build();
    }
}

现在我尝试通过 Postman 调用此服务:

选项 1 - 调用我在 API Gateway 中看到的内容:

结果:404 未找到,请参阅 AWS CloudWatch 中的相应日志。

选项 2 - 调用我的方法:

结果:403 Forbidden,AWS CloudWatch 中没有日志。

{
    "message": "Missing Authentication Token"
}

我完全理解为什么选项 1不起作用,但是选项 2出了什么问题?你能帮我理解我错过了什么吗?

标签: restamazon-web-servicesaws-lambda

解决方案


当您尝试调用不存在的 URL 时(大多数情况下)会出现此消息。

请确保您正在拨打电话http://api-gateway-name/stage-name/resource-name

此外,请确保您已部署 API。


推荐阅读