버전 비교

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

...

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

# 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-0e3593e52a4149549')
AWS_ENV = core.Environment(account=ACCOUNT, region=REGION)

class UrlShortStack(core.Stack):

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

        # The code that defines your stack goes here
        table = aws_dynamodb.Table(self, "mapping",
            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(core.Stack):
    
    def __init__(self, scope: core.Construct, id: str, **kwargs) -> None:
        super().__init__(scope, id, env=AWS_ENV, **kwargs)
        
        # lookup our pre-created VPC by ID
        vpc_env = aws_ec2.Vpc.from_lookup(self, "vpc",
            vpc_id=VPC_ID)

        Traffic(self, 'TestTraffic',
            vpc= vpc_env,
            url="https://7vzqf6htub.execute-api.ap-southeast-1.amazonaws.com/prod/2a3c26e0",
            tps=10)

...