[英]How to export already created (via web console) services to CDK locally and be able to deploy/update them?
Current situation:现在的情况:
I have an AWS API Gateway referencing some AWS Lambdas, and some Lambdas querying a DynamoDB instance.我有一个 AWS API 网关引用一些 AWS Lambdas,一些 Lambdas 查询 DynamoDB 实例。
All of the above are created and handled manually via the AWS web console.以上所有内容都是通过 AWS web 控制台手动创建和处理的。 There's no cloudformation template for that.没有 cloudformation 模板。
^ I want to be able to have that locally too using CDK: ^ 我也希望能够使用 CDK 在本地拥有它:
I want to apply some healthy developer procedures and create a CDK file system locally, for testing, manage deployment, manage versioning via GitHub or whatever AWS has to offer in that field (didn't get to that part yet).我想应用一些健康的开发人员程序并在本地创建一个 CDK 文件系统,用于测试、管理部署、通过 GitHub 或 AWS 在该领域提供的任何内容(尚未涉及该部分)管理版本控制。
I noticed that there is 0% information on how to do that.我注意到关于如何做到这一点的信息为 0%。 Most tutorials follow a situation where:大多数教程遵循以下情况:
Please help me figure our the best proper way to do that.请帮我想出最好的方法来做到这一点。 Some things that came up but didn't actually do:一些出现但实际上没有做的事情:
You must import existing resource's to CDK.您必须将现有资源导入 CDK。
https://link.medium.com/1RbcEdal4wb https://link.medium.com/1RbcEdal4wb
TL;DR Use cdk import
for supported resources. TL;DR使用cdk import
获取支持的资源。 Re-create the RestApi from an exported OpenApi Definition.从导出的 OpenApi 定义重新创建 RestApi。
cdk import
The CDK has experimental import functionality to bring existing console-created resources under CDK management. CDK 具有实验性的导入功能,可以将现有的控制台创建的资源置于 CDK 管理之下。 The cdk import CLI command piggybacks off the related CloudFormation resource import operation. cdk import CLI 命令搭载了相关的 CloudFormation 资源导入操作。
Not all resources support the import operation .并非所有资源都支持导入操作。 The AWS::Lambda::Function
and AWS::DynamoDB::Table
resources are supported.支持AWS::Lambda::Function
和AWS::DynamoDB::Table
资源。 You must also consider secondary resources, such as the Lambda's execution role ( AWS::IAM::Role
is supported for importing).您还必须考虑辅助资源,例如 Lambda 的执行角色(支持导入AWS::IAM::Role
)。
Resource importing starts with manually configuring a CDK stack that matches the existing cloud-side configuration.资源导入从手动配置与现有云端配置相匹配的 CDK 堆栈开始。 To guide your work, say, on recreating a dynamodb.Table
in CDK, consider running the DescribeTable API to get a dump of the current configuration.为了指导您的工作,例如,在 CDK 中重新创建dynamodb.Table
,请考虑运行DescribeTable API 以获取当前配置的转储。 Because of the manual work involved, it's wise to focus your importing energies on stateful resources and consider simply destroying and recreating stateless resources.由于涉及手动工作,将导入的精力集中在有状态资源上并考虑简单地销毁和重建无状态资源是明智的。
Once the app is complete, run the cdk import
command.应用程序完成后,运行cdk import
命令。 After that, the imported resources can be modified like any other CDK resource.之后,可以像修改任何其他 CDK 资源一样修改导入的资源。
AWS::ApiGateway::RestApi
is not on the list of supported resources for import 1 . AWS::ApiGateway::RestApi
不在 import 1支持的资源列表中。 A Plan B for your Api Gateway is to export your API as an OpenAPI defnition 2 . Api 网关的 B 计划是将 API 导出为 OpenAPI 定义2 。 Then pass the JSON as the API definition to CDK RestApi construct with the ApiDefinition.fromAsset method.然后使用ApiDefinition.fromAsset方法将 JSON 作为 API 定义传递给 CDK RestApi 构造。 This will create a new API, not import it per se.这将创建一个新的 API,而不是导入它本身。
AWS::ApiGateway
resources are, such as Resource, Stage, Model and Method.虽然RestApi资源本身不支持导入,但是很多相关的AWS::ApiGateway
资源是支持导入的,比如Resource, Stage, Model和Method。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.