def __init__(self, scope: Construct, id: str, **kwargs) -> None: super().__init__(scope, id, **kwargs) source_artifact = codepipeline.Artifact() cloud_assembly_artifact = codepipeline.Artifact() pipeline = CdkPipeline(self, "Pipeline", pipeline_name="MyAppPipeline", cloud_assembly_artifact=cloud_assembly_artifact, source_action=codepipeline_actions.GitHubSourceAction( action_name="GitHub", output=source_artifact, oauth_token=SecretValue.secrets_manager("GITHUB_TOKEN_NAME"), trigger=codepipeline_actions.GitHubTrigger.POLL, # Replace these with your actual GitHub project info owner="srinivasreddych", repo="cdk-pipelines"), synth_action=SimpleSynthAction.standard_npm_synth( source_artifact=source_artifact, cloud_assembly_artifact=cloud_assembly_artifact, # Use this if you need a build step (if you're not using ts-node # or if you have TypeScript Lambdas that need to be compiled). build_command="npm run build" ) )
def __init__(self, scope: Construct, id: str, **kwargs) -> None: super().__init__(scope, id, **kwargs) source_artifact = codepipeline.Artifact() cloud_assembly_artifact = codepipeline.Artifact() pipeline = CdkPipeline(self, "Pipeline", pipeline_name="MyAppPipeline", cloud_assembly_artifact=cloud_assembly_artifact, source_action=codepipeline_actions.GitHubSourceAction( action_name="GitHub", output=source_artifact, oauth_token=SecretValue.secrets_manager("pipeline_api_key"), trigger=codepipeline_actions.GitHubTrigger.POLL, # Replace these with your actual GitHub project info owner="joeycoak", repo="lab2-cdk"), synth_action=SimpleSynthAction.standard_npm_synth( source_artifact=source_artifact, cloud_assembly_artifact=cloud_assembly_artifact, # Use this if you need a build step (if you're not using ts-node # or if you have TypeScript Lambdas that need to be compiled). build_command="pip install -r requirements.txt", install_command="npm install -g aws-cdk && pip install -r requirements.txt", synth_command="cdk synth" ) )
def __init__(self, scope: core.Construct, id: str, **kwargs) -> None: super().__init__(scope, id, **kwargs) source_artifact = aws_codepipeline.Artifact() cloud_assembly_artifact = aws_codepipeline.Artifact() pipeline = CdkPipeline( self, "cdk_pipeline", pipeline_name="IntroCdkpipelinesStack_Pipeline", cloud_assembly_artifact=cloud_assembly_artifact, source_action=aws_codepipeline_actions.GitHubSourceAction( action_name="GitHub", output=source_artifact, oauth_token=SecretValue.secrets_manager( secret_id="github-token", json_field="github-token" ), owner="MasatoShima", repo="Samples-AWS-Hands-On-CDK", trigger=aws_codepipeline_actions.GitHubTrigger.POLL ), synth_action=SimpleSynthAction.standard_yarn_synth( source_artifact=source_artifact, cloud_assembly_artifact=cloud_assembly_artifact, install_command="pip install -r requirements.txt", subdirectory="./intro_cdkpipelines/" ) ) pipeline.add_application_stage( CdkpipelinesDemoStage(self, "PreProd") )
def __init__(self, scope: Construct, id: str, **kwargs) -> None: super().__init__(scope, id, **kwargs) source_artifact = codepipeline.Artifact() cloud_assembly_artifact = codepipeline.Artifact() pipeline = CdkPipeline(self, "Pipeline", pipeline_name="WebinarPipeline", cloud_assembly_artifact=cloud_assembly_artifact, source_action=codepipeline_actions.GitHubSourceAction( action_name="GitHub", output=source_artifact, oauth_token=SecretValue.secrets_manager("github-token"), trigger=codepipeline_actions.GitHubTrigger.POLL, # Replace these with your actual GitHub project info owner="rcouso", repo="cdkpipeline", branch="main"), synth_action=SimpleSynthAction( source_artifact=source_artifact, cloud_assembly_artifact=cloud_assembly_artifact, # Use this if you need a build step (if you're not using ts-node # or if you have TypeScript Lambdas that need to be compiled). install_command="npm install -g aws-cdk && pip install -r requirements.txt", build_command="pytest pipelines_webinar/unittests", synth_command="cdk synth" ) ) # PRE STAGE pre_prod_app = WebServiceStage(self, 'Pre-Prod', env={ 'account': '282334958158', 'region' : 'eu-west-1' }) pre_prod_stage = pipeline.add_application_stage(pre_prod_app) pre_prod_stage.add_actions(ShellScriptAction( action_name="Integ", run_order=pre_prod_stage.next_sequential_run_order(), additional_artifacts=[source_artifact], commands=[ "pip install -r requirements.txt", "pytest pipelines_webinar/integtests", ], use_outputs={ "SERVICE_URL": pipeline.stack_output(pre_prod_app.url_output) })) # pre_prod_stage.add_manual_approval_action(action_name='PromoteToPro') pipeline.add_application_stage(WebServiceStage(self, 'Prod', env={ 'account': '282334958158', 'region' : 'eu-west-1' }))
def __init__(self, scope: Construct, id: str, **kwargs) -> None: super().__init__(scope, id, **kwargs) source_artifact = codepipeline.Artifact() cloud_assembly_artifact = codepipeline.Artifact() github_token_secret_name = os.getenv('GITHUB_TOKEN', '') pipeline = CdkPipeline( self, "Pipeline", pipeline_name="SharedPipeline", cloud_assembly_artifact=cloud_assembly_artifact, source_action=codepipeline_actions.GitHubSourceAction( action_name="GitHub", output=source_artifact, oauth_token=SecretValue.secrets_manager( github_token_secret_name), trigger=codepipeline_actions.GitHubTrigger.POLL, owner="srethira", repo="cdk-pipeline-shared"), synth_action=SimpleSynthAction( source_artifact=source_artifact, cloud_assembly_artifact=cloud_assembly_artifact, install_command= "npm install -g aws-cdk && pip install -r requirements.txt", # build_command="mvn package", synth_command="cdk synth", copy_environment_variables=["GITHUB_TOKEN"])) pipeline.add_application_stage( SharedStage(self, 'Testing', env=Environment(account="462864815626", region="us-west-1"))) # Do this as many times as necessary with any account and region # Account and region may be different from the pipeline's. pipeline.add_application_stage( SharedStage(self, 'Prod', env=Environment(account="462864815626", region="us-west-2")))
def __init__(self, scope: Construct, id: str, vpc: Vpc, **kwargs) -> None: super().__init__(scope, id, **kwargs) self.rds = DatabaseInstance( self, "rds", master_username=USER, master_user_password=SecretValue(PASSWORD), database_name=DATABASE, vpc=vpc.vpc, engine=DatabaseInstanceEngine.POSTGRES, port=PORT, instance_type=InstanceType.of(InstanceClass.BURSTABLE3, InstanceSize.MICRO), security_groups=[vpc.sg_rds], deletion_protection=False, ) CfnOutput( self, "rds_address", value= f"postgres://{USER}:{PASSWORD}@{self.rds.db_instance_endpoint_address}:{PORT}/{DATABASE}", )
from aws_cdk import (aws_cloudwatch as cw, aws_cloudwatch_actions as cw_actions, aws_lambda, aws_logs, aws_sns, aws_sns_subscriptions, aws_sqs, core) from aws_cdk.core import (App, Duration, RemovalPolicy, SecretValue, Stack, Token) # You need to manually setup this 'your_secret_id' in Secrets Manager # before deploy CDK with 3 fields: bot_id, token of the telegram_bot # and chat_id of the telegram chat where the bot will write the messages. SECRET_ID = 'your_secret_id' bot_id = Token.as_string( SecretValue.secrets_manager(secret_id=SECRET_ID, json_field='bot_id')) token = Token.as_string( SecretValue.secrets_manager(secret_id=SECRET_ID, json_field='token')) chat_id = Token.as_string( SecretValue.secrets_manager(secret_id=SECRET_ID, json_field='chat_id')) class LambdaStack(Stack): def __init__(self, app: App, id: str, **kwargs) -> None: super().__init__(app, id, **kwargs) # ======================================== # LAMBDA # ======================================== app_code = aws_lambda.Code.asset("./src")
def __init__(self, scope: Construct, id: str, **kwargs) -> None: super().__init__(scope, id, **kwargs) source_artifact = codepipeline.Artifact() cloud_assembly_artifact = codepipeline.Artifact() github_token_secret_name = os.getenv('GITHUB_TOKEN', '') pipeline = CdkPipeline( self, "Pipeline", pipeline_name="MyAppPipeline", cloud_assembly_artifact=cloud_assembly_artifact, source_action=codepipeline_actions.GitHubSourceAction( action_name="GitHub", output=source_artifact, oauth_token=SecretValue.secrets_manager( github_token_secret_name), trigger=codepipeline_actions.GitHubTrigger.POLL, owner="srethira", repo="cdk-pipeline-ecs", branch="master"), # Current limitation: generate CodeBuild reports within @aws-cdk/cdk-pipelines # https://github.com/aws/aws-cdk/issues/10464 synth_action=SimpleSynthAction( source_artifact=source_artifact, cloud_assembly_artifact=cloud_assembly_artifact, # enable privileged mode for docker-in-docker (for asset bundling) environment=dict(privileged=True), install_command="pipeline/bin/install.sh", build_command="python -m unittest test/test_*", synth_command="cdk synth", copy_environment_variables=["GITHUB_TOKEN"])) # Do this as many times as necessary with any account and region for testing # Account and region may be different from the pipeline's. test = ApplicationStage(self, 'Testing', env=Environment(account="462864815626", region="us-west-1")) test_stage = pipeline.add_application_stage(test) test_stage.add_actions( ShellScriptAction( action_name='validate', commands=['curl -Ssf $ENDPOINT_URL/container'], use_outputs=dict(ENDPOINT_URL=pipeline.stack_output( test.load_balancer_address)))) test_stage.add_actions( ShellScriptAction(action_name='integration', commands=['python -m unittest test/test_*'], additional_artifacts=[source_artifact])) # Do this as many times as necessary with any account and region for prod prod = ApplicationStage(self, 'Prod', env=Environment(account="462864815626", region="us-west-2")) prod_stage = pipeline.add_application_stage(prod) prod_stage.add_actions( ShellScriptAction( action_name='validate', commands=['curl -Ssf $ENDPOINT_URL/container'], use_outputs=dict(ENDPOINT_URL=pipeline.stack_output( prod.load_balancer_address)))) prod_stage.add_actions( ShellScriptAction(action_name='integration', commands=['python -m unittest test/test_*'], additional_artifacts=[source_artifact]))
def __init__(self, scope: Construct, id: str, **kwargs) -> None: super().__init__(scope, id, **kwargs) source_artifact = codepipeline.Artifact() cloud_assembly_artifact = codepipeline.Artifact() pipeline = CdkPipeline( self, "Pipeline", pipeline_name="WebinarPipeline", cloud_assembly_artifact=cloud_assembly_artifact, source_action=codepipeline_actions.GitHubSourceAction( action_name="GitHub", output=source_artifact, oauth_token=SecretValue.secrets_manager("github-token"), trigger=codepipeline_actions.GitHubTrigger.POLL, # Replace these with your actual GitHub project info owner="rcouso", repo="cdkpipeline", branch="main"), synth_action=SimpleSynthAction( source_artifact=source_artifact, cloud_assembly_artifact=cloud_assembly_artifact, # Use this if you need a build step (if you're not using ts-node # or if you have TypeScript Lambdas that need to be compiled). install_command= "npm install -g aws-cdk && pip install -r requirements.txt", build_command="pytest pipelines_webinar/unittests", synth_command="cdk synth")) # DEV STAGE dev_app = WebServiceStage(self, 'Dev', env={ 'account': '722610601746', 'region': 'eu-west-1' }) dev_stage = pipeline.add_application_stage(dev_app) dev_stage.add_actions( ShellScriptAction( action_name="Integ", run_order=dev_stage.next_sequential_run_order(), additional_artifacts=[source_artifact], environment=BuildEnvironment( environment_variables={ 'CODECOV_TOKEN': aws_codebuild.BuildEnvironmentVariable( value='9e4d7998-7a8e-45a2-81fe-8a9c761cb03a') }), commands=[ "pip install -r requirements.txt", "pytest pipelines_webinar/integtests", "echo 'TOKEN='$CODECOV_TOKEN" # coverage # "pip install coverage", # "coverage run -a --source pipelines_webinar/unittests", # "coverage run -a --source pipelines_webinar/integtests", # "bash pipelines_webinar/coverage.sh" ], use_outputs={ "SERVICE_URL": pipeline.stack_output(dev_app.url_output) })) dev_stage.add_manual_approval_action(action_name='PromoteToPro') # PRO STAGE pipeline.add_application_stage( WebServiceStage(self, 'Prod', env={ 'account': '807034265755', 'region': 'eu-west-1' }))