How to create custom construct library for aws-cdk in python

℡╲_俬逩灬. 提交于 2021-01-29 06:06:27

问题


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

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.

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:

Disclaimer: Code below Might not be correct

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
                                )

Any help Devs how to?


回答1:


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.



来源:https://stackoverflow.com/questions/59986081/how-to-create-custom-construct-library-for-aws-cdk-in-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!