Problem无法使用CDKTF在AWS中创建安全组规则

Code

import cdktf_cdktf_provider_aws.security_group as SecurityGroup_
self.security_group_ = SecurityGroup_.SecurityGroup(self.scope_object, id_=self.id, name=self.name, vpc_id=self.vpc_id, ingress=[{"from_port":"3306","to_port":"3306"}])


Error

   29:         "ingress": [
   30:           {
   31:             "cidr_blocks": null,
   32:             "description": "smartstack_dependency",
   33:             "from_port": null,
   34:             "ipv6_cidr_blocks": null,
   35:             "prefix_list_ids": null,
   36:             "protocol": "tcp",
   37:             "security_groups": null,
   38:             "self": null,
   39:             "to_port": null
   40:           }
   41:         ],

 The argument "ingress.0.to_port" is required, but no definition was found.

已try 以下代码-

import cdktf_cdktf_provider_aws.security_group as SecurityGroup_
self.security_group_ = SecurityGroup_.SecurityGroup(self.scope_object, id_=self.id, name=self.name, vpc_id=self.vpc_id, ingress=[{"from_port":"3306","to_port":"3306"}])

推荐答案

将代码更改为

self.security_group_ = SecurityGroup_.SecurityGroup(
self.scope_object, 
id_=self.id, 
name=self.name, 
vpc_id=self.vpc_id, 
ingress=[SecurityGroup_.SecurityGroupIngress(from_port=3306,to_port=3306, "security_groups":['test-sg'])])

Enress参加了Obj SecurityGroupIngress班的list

Python相关问答推荐

替换字符串中的多个重叠子字符串

在Python中处理大量CSV文件中的数据

类型错误:输入类型不支持ufuncisnan-在执行Mann-Whitney U测试时[SOLVED]

如何在虚拟Python环境中运行Python程序?

Streamlit应用程序中的Plotly条形图中未正确显示Y轴刻度

移动条情节旁边的半小提琴情节在海运

使用NeuralProphet绘制置信区间时出错

改进大型数据集的框架性能

将pandas导出到CSV数据,但在此之前,将日期按最小到最大排序

在www.example.com中使用`package_data`包含不包含__init__. py的非Python文件

如何在Python中使用Pandas将R s Tukey s HSD表转换为相关矩阵''

为什么'if x is None:pass'比'x is None'单独使用更快?

基于多个数组的多个条件将值添加到numpy数组

不允许 Select 北极滚动?

如何在Python中自动创建数字文件夹和正在进行的文件夹?

设置索引值每隔17行左右更改的索引

从列表中分离数据的最佳方式

如何在python tkinter中绑定键盘上的另一个回车?

如何从一个维基页面中抓取和存储多个表格?

如何将ManyToManyfield用于Self类