How to use aws-cdk - 10 common examples

To help you get started, we’ve selected a few aws-cdk examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github seagull-js / seagull / packages / deploy-aws / src / templates / seagull_pipeline.ts View on Github external
async createPipeline() {
    setCredsByProfile(this.profile)
    // preparations for deployment
    const isTest = this.stage === 'test'
    const suffix = `${isTest ? `-${this.branch}-test` : ''}-ci`
    const pkgJson = require(`${this.appPath}/package.json`)
    const name = `${pkgJson.name}${suffix}`.replace(/[^0-9A-Za-z-]/g, '')
    const sdk = new SDK({})
    const account = await sdk.defaultAccount()
    const stackProps = { env: { account, region: this.region } }
    const props = { projectName: name, sdk, stackProps }
    const actions = this.actions

    // construct the stack and the app
    const pipelineApp = new SeagullApp(props)
    const stack = pipelineApp.stack
    const principal = 'codebuild.amazonaws.com'
    const role = stack.addIAMRole('role', principal, actions)
    const pipeline = stack.addPipeline('pipeline')
    const token = this.githubToken
    const tokenName = token ? `${name}-github` : this.ssmParam || undefined
    const secretParams = { ssmHandler: this.ssm, token, tokenName }
    const ssmSecret = await handleSSMSecret(secretParams)
    const gitDataProps = {
github seagull-js / seagull / packages / deploy-aws / src / seagull_app.ts View on Github external
async diffStack() {
    const sdk = new cdk.SDK({})
    const synthStack = this.synthesizeStack(this.projectName)
    const cfn = await sdk.cloudFormation(synthStack.environment, 0)
    const templateData = { StackName: synthStack.name }
    const template = await cfn.getTemplate(templateData).promise()
    const body = template.TemplateBody
    const curTemplate = (body && yaml.parse(body, { schema: 'yaml-1.1' })) || {}
    const logicalToPathMap = lib.createLogicalToPathMap(synthStack)
    const diff = cfnDiff.diffTemplate(curTemplate, synthStack.template)
    // tslint:disable-next-line:no-unused-expression
    diff.isEmpty && lib.noChangesInDiff()
    cfnDiff.formatDifferences(process.stdout, diff, logicalToPathMap)
  }
}
github aws / aws-cdk / packages / aws-cdk-sns / lib / topic-ref.ts View on Github external
const subscriptionName = queue.name + 'Subscription';
        if (this.tryFindChild(subscriptionName)) {
            throw new Error(`A subscription between the topic ${this.name} and the queue ${queue.name} already exists`);
        }

        // we use the queue name as the subscription's. there's no meaning to subscribing
        // the same queue twice on the same topic.
        const sub = new Subscription(this, subscriptionName, {
            topic: this,
            endpoint: queue.queueArn,
            protocol: SubscriptionProtocol.Sqs
        });

        // add a statement to the queue resource policy which allows this topic
        // to send messages to the queue.
        queue.addToResourcePolicy(new PolicyStatement()
            .addResource(queue.queueArn)
            .addAction('sqs:SendMessage')
            .addServicePrincipal('sns.amazonaws.com')
            .setCondition('ArnEquals', { 'aws:SourceArn': this.topicArn }));

        return sub;
    }
github seagull-js / seagull / packages / deploy-aws / src / templates / seagull_project.ts View on Github external
async createBareApp() {
    const account = this.account || (await new SDK({}).defaultAccount())
    const itemsProps = {
      accountId: (await aws.getAccountId(this.sts)) || '',
      branch: this.branch,
      projectName: this.pkgJson.name,
      region: this.region,
      stage: this.stage,
      topic: 'items',
    }
    const appProps = {
      addAssets: true,
      appPath: this.appPath,
      itemsBucket: lib.getBucketName(itemsProps),
      projectName: this.getAppName(),
      stackProps: { env: { account, region: this.region } },
    }
    return new SeagullApp(appProps)
github seagull-js / seagull / packages / pipeline / src / pipeline.ts View on Github external
constructor(appPath: string, opts: Options) {
    this.appPath = appPath
    this.opts = opts
    this.projectName = `${require(`${appPath}/package.json`).name}-pipeline`
    this.sdk = new cdk.SDK({})
    this.logicalToPathMap = {}
    this.synthStack = {} as SynthesizedStack
  }
github seagull-js / seagull / packages / deploy-aws / src / seagull_app.ts View on Github external
async deployStack() {
    const sdk = new cdk.SDK({})
    const synthStack = this.synthesizeStack(this.projectName)
    const env = synthStack.environment
    await cdk.bootstrapEnvironment(env, sdk, 'CDKToolkit', undefined)
    const toolkitInfo = await cdk.loadToolkitInfo(env, sdk, 'CDKToolkit')
    await cdk.deployStack({ sdk, stack: synthStack, toolkitInfo })
  }
github seagull-js / seagull / packages / pipeline / src / pipeline.ts View on Github external
private async deployCDKPipeline() {
    const env = this.synthStack.environment
    const toolkitInfo = await cdk.loadToolkitInfo(env, this.sdk, 'CDKToolkit')
    await cdk.bootstrapEnvironment(env, this.sdk, 'CDKToolkit', undefined)
    const sdk = this.sdk
    const stack = this.synthStack
    await cdk.deployStack({ sdk, stack, toolkitInfo })
  }
github seagull-js / seagull / packages / deploy / src / deploy.ts View on Github external
private async deployCDKApp() {
    const env = this.synthStack.environment
    const toolkitInfo = await cdk.loadToolkitInfo(env, this.sdk, 'CDKToolkit')
    await cdk.bootstrapEnvironment(env, this.sdk, 'CDKToolkit', undefined)
    const stack = this.synthStack
    await cdk.deployStack({ sdk: this.sdk, stack, toolkitInfo })
    return true
  }
}
github seagull-js / seagull / packages / deploy-aws / src / seagull_app.ts View on Github external
async destroyStack() {
    const sdk = new cdk.SDK({})
    const synthStack = this.synthesizeStack(this.projectName)
    const env = synthStack.environment
    await cdk.bootstrapEnvironment(env, sdk, 'CDKToolkit', undefined)
    await cdk.destroyStack({ sdk, stack: synthStack })
  }
github seagull-js / seagull / packages / deploy-aws / src / seagull_app.ts View on Github external
async deployStack() {
    const sdk = new cdk.SDK({})
    const synthStack = this.synthesizeStack(this.projectName)
    const env = synthStack.environment
    await cdk.bootstrapEnvironment(env, sdk, 'CDKToolkit', undefined)
    const toolkitInfo = await cdk.loadToolkitInfo(env, sdk, 'CDKToolkit')
    await cdk.deployStack({ sdk, stack: synthStack, toolkitInfo })
  }