Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: __init__() got an unexpected keyword argument 'vpc_id' #3

Open
Souvikde07 opened this issue Dec 7, 2021 · 0 comments
Open

Comments

@Souvikde07
Copy link

While creating an EC2 instance using cdk for aws, i am getting the error as mentioned above.

Error message:
Souvik De@DEMOLITION-PC MINGW64 ~/Desktop/Work/Working/AWS CDK/my-first-cdk-project (master)
$ cdk ls
Traceback (most recent call last):
File "C:\Users\Souvik De\Desktop\Work\Working\AWS CDK\my-first-cdk-project\app.py", line 18, in
CustomEc2Stack(app,"my-web-server-stack-01",env = env_prod)
File "C:\Users\Souvik De\Desktop\Work\Working\AWS CDK\my-first-cdk-project.venv\lib\site-packages\jsii_runtime.py", line 86, in call
inst = super().call(*args, **kwargs)
File "C:\Users\Souvik De\Desktop\Work\Working\AWS CDK\my-first-cdk-project\resource_stacks\custom_ec2.py", line 10, in init
vpc = _ec2.Vpc(self,
File "C:\Users\Souvik De\Desktop\Work\Working\AWS CDK\my-first-cdk-project.venv\lib\site-packages\jsii_runtime.py", line 86, in call
inst = super().call(*args, **kwargs)
TypeError: init() got an unexpected keyword argument 'vpc_id'
Subprocess exited with error 1

My code:
custom_ec2.py:
from aws_cdk import core as cdk

from aws_cdk import (aws_ec2 as _ec2, core)

class CustomEc2Stack(cdk.Stack):

def __init__(self, scope: cdk.Construct, construct_id: str, **kwargs) -> None:
    super().__init__(scope, construct_id, **kwargs)

    vpc = _ec2.Vpc(self,
                    "importedVPC",
                    vpc_id="vpc-885898e3")
    
    # Read Bootstrap script


    # Webserver instance 001
    web_server = _ec2.Instance(self,
                                "webserver007Id",
                                instance_type=_ec2.InstanceType(instance_type_identifier="t2.micro"),
                                instance_name="webserver007",
                                machine_image=_ec2.MachineImage.generic_linux(
                                    {"ap-south-1":"ami-052cef05d01020f1d"}
                                ),
                                vpc=vpc,
                                vpc_subnets=_ec2.SubnetSelection(
                                    subnet_type=_ec2.SubnetType.PUBLIC
                                )
                                )

app.py:
#!/usr/bin/env python3
import os

from aws_cdk import core as cdk
from aws_cdk import core

from resource_stacks.custom_vpc import CustomVpcStack
from resource_stacks.custom_ec2 import CustomEc2Stack

app = core.App()

#Global declaration of environment:
env_prod = core.Environment(account="426945086755",region="ap-south-1")

#custom VPC Stack:
CustomVpcStack(app, "my-custom-vpc-stack", env = env_prod)
#custom EC2 Stack:
CustomEc2Stack(app,"my-web-server-stack-01",env = env_prod)
#Custom Ec2 instance profile stack

core.Tag.add(app, key = "stack-team-support-email",
value= app.node.try_get_context('envs')['prod']['stack-team-support-email']),

core.Tag.add(app, key = "stack-level-tagging",
value= "sample_tag_value")

app.synth()

bootstrap_script:
install_httpd.sh:
#!/bin/bash
sudo yum install -y httpd
sudo chkconfig httpd on
sudo service httpd start

If anyone could help me with the above problem. I would be greatfull. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant