Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'aws-cdk' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.
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 = {
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)
}
}
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;
}
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)
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
}
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 })
}
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 })
}
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
}
}
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 })
}
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 })
}