버전 비교

  • 이 줄이 추가되었습니다.
  • 이 줄이 삭제되었습니다.
  • 서식이 변경되었습니다.

...

코드 블럭
languagepy
themeRDark
titleurl_shrotener_stack.py
linenumberstrue
from aws_cdk import core, aws_dynamodb, aws_lambda, aws_apigateway, aws_
from traffic import Traffic
import os


# we need default values here since aws-cdk-examples build synthesizes the app
ACCOUNT= os.environ['CDK_DEFAULT_ACCOUNT']
REGION = os.environ['CDK_DEFAULT_REGION']
VPC_ID = os.environ.get('TESTENV_VPC_ID', 'vpc-0e680e107cb16f0c9')
AWS_ENV = Environment(account=ACCOUNT, region=REGION)

class UrlShortStack(core.Stack):

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

        # The code that defines your stack goes here
        table = aws_dynamodb.Table(self, "mapping-table",
            partition_key = aws_dynamodb.Attribute(name="id",type=aws_dynamodb.AttributeType.STRING))
            
        function = aws_lambda.Function(self, "backend",
            runtime=aws_lambda.Runtime.PYTHON_3_7,
            handler="handler.main",
            code=aws_lambda.Code.asset("./lambda"))
        
        table.grant_read_write_data(function)
        function.add_environment("TABLE_NAME", table.table_name)
        
        api = aws_apigateway.LambdaRestApi(self, "api", handler=function)
        
class TrafficStack(TestEnvStackcore.Stack):
    
    def __init__(self, scope: core.Construct, id: str, **kwargs) -> None:
        super().__init__(scope, id, **kwargs)
        
        # lookup our pre-created VPC by ID
        vpc_env = aws_ec2.Vpc.from_lookup(self, "vpc", vpc_id=VPC_ID)
		
		# lookup our pre-created VPC by ID
		test_url = 'https://cdk.awsdemokr.com/715a930b'

        Traffic(self, 'TestTraffic', vpc= vpc_env, url=test_url, tps=10)
            

...

코드 블럭
languagepy
themeRDark
title url_shrotener_stack.py for cdk-watchful
linenumberstrue
from aws_cdk import core, aws_dynamodb, aws_lambda, aws_apigateway, aws_
from testenvtraffic import TestEnvStackTraffic
from traffic import Trafficos
from cdk_watchful import Watchful

class UrlShortStack(TestEnvStack):

    def __init__(self, scope: core.Construct, id: str, **kwargs) -> None:
        super().__init__(scope, id# we need default values here since aws-cdk-examples build synthesizes the app
ACCOUNT= os.environ['CDK_DEFAULT_ACCOUNT']
REGION = os.environ['CDK_DEFAULT_REGION']
VPC_ID = os.environ.get('TESTENV_VPC_ID', 'vpc-0e680e107cb16f0c9')
AWS_ENV = Environment(account=ACCOUNT, region=REGION)


class UrlShortStack(core.Stack):

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

        # The code that defines your stack goes here
        table = aws_dynamodb.Table(self, "mapping-table",
            partition_key = aws_dynamodb.Attribute(name="id",type=aws_dynamodb.AttributeType.STRING))
            
        function = aws_lambda.Function(self, "backend",
            runtime=aws_lambda.Runtime.PYTHON_3_7,
            handler="handler.main",
            code=aws_lambda.Code.asset("./lambda"))
        
        table.grant_read_write_data(function)
        function.add_environment("TABLE_NAME", table.table_name)
        
        api = aws_apigateway.LambdaRestApi(self, "api", handler=function)
        
        wf = Watchful(self, 'monitoring', alarm_email='meelong0@studydevscv@studydev.com')
        wf.watch_scope(self)


class TrafficStack(TestEnvStackcore.Stack):
    
    def __init__(self, scope: core.Construct, id: str, **kwargs) -> None:
        super().__init__(scope, id, **kwargs)
        
        Traffic(self, 'TestTraffic',
    # lookup our pre-created VPC by ID
        vpc_env = self.testenv_vpc,
            url=aws_ec2.Vpc.from_lookup(self, "vpc", vpc_id=VPC_ID)
		
		# lookup our pre-created VPC by ID
		test_url = 'https://cdk.awsdemokr.com/715a930b',

        Traffic(self, 'TestTraffic', vpc= vpc_env, url=test_url, tps=10)


cdk-watchful 배포

코드 블럭
languagebash
themeDJango
title모든 cdk 스택 배포
cdk deploy "*"

...