在放大自定义资源中引用CDK的REST API资源

发布于 2025-02-04 09:47:14 字数 750 浏览 3 评论 0原文

我需要自定义REST API端点的方法处理程序,并将其指向SQS,而不是lambda函数。我正在暂停尝试,以获取对RESTAPI对象的完整引用...

RESTAPI对象我从RESTAPI.FROMRESTAPIID不完整。我不能这样做:

const restApi = apigateway.RestApi.fromRestApiId(this, 'RestApi', dependencies.api.rest.ApiId);
const queueResource = restApi.root.resourceForPath('/webhooks');

...没有得到此错误: 错误:使用FrofRestapiid()导入时未配置root。 )API。

使用FrofRestApiatTributes ( 找到对的参考。 restapi.fromrestapiattributes的文档显示了这一点,但是我没有props

const api = RestApi.fromRestApiAttributes(this, 'RestApi', {
  restApiId: props.restApiId,
  rootResourceId: props.rootResourceId,
});

有人知道如何访问rootresourceid吗?

I need to customize the method handler for a REST API endpoint and point it to SQS instead of a Lambda function. I'm stalling out trying to get a full reference to the RestApi object...

The RestApi object I get back from RestApi.fromRestApiId is incomplete; I can't do this:

const restApi = apigateway.RestApi.fromRestApiId(this, 'RestApi', dependencies.api.rest.ApiId);
const queueResource = restApi.root.resourceForPath('/webhooks');

...without getting this error:
Error: root is not configured when imported using fromRestApiId(). Use fromRestApiAttributes() API instead.

I can't use RestApi.fromRestApiAttributes as that requires the rootResourceId -- which I can't seem to find a reference to. The documentation for RestApi.fromRestApiAttributes shows this, but I don't have props:

const api = RestApi.fromRestApiAttributes(this, 'RestApi', {
  restApiId: props.restApiId,
  rootResourceId: props.rootResourceId,
});

Does anyone know how to access the rootResourceId?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浅黛梨妆こ 2025-02-11 09:47:14

root资源/)ID是一个字母数字字符串,例如4cfzeywftb,可以在控制台面包屑中找到:

APIs > API (076t2zozc0) > Resources> / (4cfzeywftb)

或通过调用get-code> get-code> get-resources

aws apigateway get-resources --rest-api-id 076t2zozc0
{
    "items": [
        {
            "id": "4cfzeywftb",
            "path": "/",
            "resourceMethods": {
                "ANY": {}
            }
        },
        {
            "id": "36g7tq",
            "parentId": "4cfzeywftb",
            "pathPart": "{proxy+}",
            "path": "/{proxy+}",
            "resourceMethods": {
                "ANY": {}
            }
        }
    ]
}

The root resource (/) id is a alphanumeric string like 4cfzeywftb, which can be found in the console breadcrumbs:

APIs > API (076t2zozc0) > Resources> / (4cfzeywftb)

or by calling get-resources:

aws apigateway get-resources --rest-api-id 076t2zozc0
{
    "items": [
        {
            "id": "4cfzeywftb",
            "path": "/",
            "resourceMethods": {
                "ANY": {}
            }
        },
        {
            "id": "36g7tq",
            "parentId": "4cfzeywftb",
            "pathPart": "{proxy+}",
            "path": "/{proxy+}",
            "resourceMethods": {
                "ANY": {}
            }
        }
    ]
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文