简体   繁体   English

如何将 aws cdk 自定义构造库作为 API 托管

[英]How to host aws cdk custom construct library as an API

Few days back I asked a question to stack overflow community at about custom construct library Question几天前,我在关于自定义构造库的问题上向堆栈溢出社区提出了一个问题

Although I didn't got the exact answer I was looking for.虽然我没有得到我想要的确切答案。 But somehow I managed to create a custom construct library.但不知何故,我设法创建了一个自定义构造库。 But now I have another query on how to host the CDK App as an API.但是现在我有另一个关于如何将 CDK 应用程序作为 API 托管的问题。

Below is the snapshot of custom construct library:以下是自定义构造库的快照:

test_ec2 = ec2.Instance(self, "APIInstance", 
                                vpc=my_vpc,
                                machine_image=ec2.AmazonLinuxImage(
                                        generation=ec2.AmazonLinuxGeneration.AMAZON_LINUX
                                ),
                                key_name="test-cdk",
                                instance_name=inst-name
                                )

If I want to host above AWS CDK Application as an API that will accept a string for the variable inst-name and will create a EC2 instance.如果我想将 AWS CDK 应用程序作为 API 托管,该 API 将接受变量inst-name的字符串并创建 EC2 实例。 I tried creating it as an lambda function but not sure how to manage "node dependencies and python dependencies" at same time.我尝试将它创建为 lambda 函数,但不确定如何同时管理“节点依赖项和 python 依赖项”。

Can it be done using an already created EC2 Instance(attaching an IAM Role with permission of cloudformation) and accepting HTTP requests (But don't know how?) Is this making sense?是否可以使用已经创建的 EC2 实例(在获得 cloudformation 许可的情况下附加 IAM 角色)并接受 HTTP 请求(但不知道如何?)这是否有意义?

Thank You in advance to all the devs.提前感谢所有开发人员。

There are many ways to do this.有很多方法可以做到这一点。 I think the simplest would be to syntesize your cloudformation templates and publish them to S3 ahead of time and use API gateway with a REST API and with AWS request type integration that would create the Cloudformation stack.我认为最简单的方法是合成您的 cloudformation 模板并提前将它们发布到 S3,并使用 API 网关与 REST API 和 AWS 请求类型集成来创建 Cloudformation 堆栈。

Here's a tutorial that explains how to build a REST API with AWS API integration: https://docs.aws.amazon.com/apigateway/latest/developerguide/getting-started-aws-proxy.html这是一个教程,解释了如何使用 AWS API 集成构建 REST API: https : //docs.aws.amazon.com/apigateway/latest/developerguide/getting-started-aws-proxy.html

Just this is for SNS:ListTopics action, but you would want cloudformation:CreateStack action instead.这只是用于 SNS:ListTopics 操作,但您可能需要cloudformation:CreateStack操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM