Giter Site home page Giter Site logo

miztiik / my-first-cdk-project Goto Github PK

View Code? Open in Web Editor NEW
72.0 11.0 185.0 1.65 MB

A hands on repo with multiple demonstrations on CDK: Used by Udemy Course🎓

Home Page: https://www.udemy.com/course/aws-cloud-development-kit-from-beginner-to-professional/?referralCode=E15D7FB64E417C547579

Python 60.93% Shell 0.50% HTML 1.88% CSS 29.74% JavaScript 6.96%
aws cdk miztiik cloud-development-kit udemy-course-project

my-first-cdk-project's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

my-first-cdk-project's Issues

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

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.

Import resources from another stack

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.