miztiik / my-first-cdk-project Goto Github PK
View Code? Open in Web Editor NEWA hands on repo with multiple demonstrations on CDK: Used by Udemy Course🎓
A hands on repo with multiple demonstrations on CDK: Used by Udemy Course🎓
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.
Hello,
Thank you so much for your wonderful tutorial.
In fact I have a question related to the import resources from another stacks.
So usually, we export the resources using CfnOutput like that:
customvpcid=core.CfnOutput(self,
"CustomVpcIdOutput",
value=prod_vpc.vpc_id,
export_name="customvpcid"
)
But, how to import it in another stack ? I understand that we can use "isDefault" in the ec2.Vpc.from_lookup
Or by adding directly the VPC ID.
But I really want to know how to pass the ID from the export_name to another stack in the right way.
Same question for Ec2 ID.
I really appreciate it if you could answer my question.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.