如何在python中为AWS-CDK创建自定义构造库 [英] How to create custom construct library for aws-cdk in python

查看:86
本文介绍了如何在python中为AWS-CDK创建自定义构造库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近,我一直在使用aws-cdk创建EC2,VPC和S3服务.

Recently I have been using aws-cdk to create EC2, VPC and S3 services.

但是,如果要在python中创建我的自定义EC2库(不使用JSII),则要比使用aws_cdk的aws_ec2库实际创建EC2实例和VPC多得多.

But if I want to create my custom EC2 Library in python(not using JSII) than will be using aws_cdk's aws_ec2 library to actually create the EC2 Instance and a VPC.

自定义库将接受以下参数,例如实例名称(String) InstanceType(String) MachineImage(String)子网类型(字符串)

The custom library will accept arguments like Instance Name(String) , InstanceType(String) , MachineImage(String) , Subnet Type (String)

比起以下参数,将引用以下参数:

Than this arguments will be refer like below:

dummy_ec2 = ec2.Instance(self, <InstanceName>, 
                                vpc=<Created_VPC>,
                                instance_type=ec2.InstanceType(<InstanceType>),
                                machine_image=ec2.AmazonLinuxImage(
                                        generation=ec2.AmazonLinuxGeneration.AMAZON_LINUX,
                                        edition=ec2.AmazonLinuxEdition.STANDARD,
                                        virtualization=ec2.AmazonLinuxVirt.HVM,
                                        storage=ec2.AmazonLinuxStorage.GENERAL_PURPOSE
                                ),
                                key_name="demo-key",
                                vpc_subnets=ec2.SubnetSelection(subnet_type=<subnet_type>),
                                role=self.my_role
                                )

任何帮助Devs怎么做?

Any help Devs how to?

推荐答案

此帖子

This post use existing vpc and security group when adding an ec2 instance might be able to help. Your code looks like you're on the right path. Certain resources definitions in AWS CDK involve many objects and can results in verbose code.

这篇关于如何在python中为AWS-CDK创建自定义构造库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆