-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CDK pipeline to deploy to cross account
- Loading branch information
0 parents
commit 385ce00
Showing
14 changed files
with
5,015 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
*.js | ||
!jest.config.js | ||
*.d.ts | ||
node_modules | ||
|
||
# CDK asset staging directory | ||
.cdk.staging | ||
cdk.out | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
*.ts | ||
!*.d.ts | ||
|
||
# CDK asset staging directory | ||
.cdk.staging | ||
cdk.out |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Welcome to your CDK TypeScript project | ||
|
||
This is a blank project for CDK development with TypeScript. | ||
|
||
The `cdk.json` file tells the CDK Toolkit how to execute your app. | ||
|
||
## Useful commands | ||
|
||
* `npm run build` compile typescript to js | ||
* `npm run watch` watch for changes and compile | ||
* `npm run test` perform the jest unit tests | ||
* `cdk deploy` deploy this stack to your default AWS account/region | ||
* `cdk diff` compare deployed stack with current state | ||
* `cdk synth` emits the synthesized CloudFormation template |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export const accountA="1xxxxxxxxxxx" | ||
export const accountB="038xxxxxxxxx" | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#!/usr/bin/env node | ||
import 'source-map-support/register'; | ||
import * as cdk from 'aws-cdk-lib'; | ||
import { CdkPipelineDemoStack } from '../lib/cdk-pipeline-demo-stack'; | ||
|
||
const id= "Account A id here" | ||
|
||
const app = new cdk.App(); | ||
new CdkPipelineDemoStack(app, 'CdkPipelineDemoStack', { | ||
env: { | ||
region: 'us-east-1', | ||
account: id, | ||
} | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
{ | ||
"app": "npx ts-node --prefer-ts-exts bin/cdk-pipeline-demo.ts", | ||
"watch": { | ||
"include": [ | ||
"**" | ||
], | ||
"exclude": [ | ||
"README.md", | ||
"cdk*.json", | ||
"**/*.d.ts", | ||
"**/*.js", | ||
"tsconfig.json", | ||
"package*.json", | ||
"yarn.lock", | ||
"node_modules", | ||
"test" | ||
] | ||
}, | ||
"context": { | ||
"@aws-cdk/aws-apigateway:usagePlanKeyOrderInsensitiveId": true, | ||
"@aws-cdk/core:stackRelativeExports": true, | ||
"@aws-cdk/aws-rds:lowercaseDbIdentifier": true, | ||
"@aws-cdk/aws-lambda:recognizeVersionProps": true, | ||
"@aws-cdk/aws-cloudfront:defaultSecurityPolicyTLSv1.2_2021": true, | ||
"@aws-cdk-containers/ecs-service-extensions:enableDefaultLogDriver": true, | ||
"@aws-cdk/aws-ec2:uniqueImdsv2TemplateName": true, | ||
"@aws-cdk/core:checkSecretUsage": true, | ||
"@aws-cdk/aws-iam:minimizePolicies": true, | ||
"@aws-cdk/core:target-partitions": [ | ||
"aws", | ||
"aws-cn" | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module.exports = { | ||
testEnvironment: 'node', | ||
roots: ['<rootDir>/test'], | ||
testMatch: ['**/*.test.ts'], | ||
transform: { | ||
'^.+\\.tsx?$': 'ts-jest' | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { Stack, StackProps } from 'aws-cdk-lib'; | ||
import { Construct } from 'constructs'; | ||
import {CodeBuildStep, CodePipeline, CodePipelineSource} from "aws-cdk-lib/pipelines"; | ||
// import * as sqs from 'aws-cdk-lib/aws-sqs'; | ||
import * as codecommit from 'aws-cdk-lib/aws-codecommit' | ||
import { Pipeline } from 'aws-cdk-lib/aws-codepipeline'; | ||
import { PipelineStage } from './pipeline-stage'; | ||
|
||
|
||
|
||
export class CdkPipelineDemoStack extends Stack { | ||
constructor(scope: Construct, id: string, props?: StackProps) { | ||
super(scope, id, props); | ||
|
||
const repo= new codecommit.Repository(this, 'CDKpipelinerepo', { | ||
repositoryName: "CDKpipelinerepo" | ||
}); | ||
const pipeline = new CodePipeline(this, 'Pipeline', { | ||
crossAccountKeys: true, | ||
pipelineName: 'Cdkpipeline', | ||
synth: new CodeBuildStep('SynthStep', { | ||
input: CodePipelineSource.codeCommit(repo, 'master'), | ||
installCommands: [ | ||
'npm install -g aws-cdk' | ||
], | ||
commands: [ | ||
'npm ci', | ||
'npm run build', | ||
'npx cdk synth' | ||
] | ||
} | ||
) | ||
}); | ||
const deploy = new PipelineStage(this, 'Deploy'); | ||
const deployStage = pipeline.addStage(deploy); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { SqsStack } from './sqs-stack' | ||
import { Stage, StageProps } from 'aws-cdk-lib'; | ||
import { Construct } from 'constructs'; | ||
import { accountA , accountB} from '../accoountinfo' | ||
import * as cdk from 'aws-cdk-lib'; | ||
|
||
|
||
|
||
|
||
export class PipelineStage extends Stage { | ||
constructor(scope: Construct, id: string, props?: StageProps) { | ||
super(scope, id, props); | ||
|
||
new SqsStack(this, 'sqs', { | ||
env: { account: accountA , region: 'us-east-1'}, | ||
prefix: 'testing' | ||
} ); | ||
|
||
new SqsStack(this, 'sqs1', { | ||
env: { account: accountB , region: 'us-east-1'}, | ||
prefix: 'production' | ||
} ); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { Stack, StackProps } from 'aws-cdk-lib'; | ||
import { Construct } from 'constructs'; | ||
import * as sqs from 'aws-cdk-lib/aws-sqs'; | ||
import * as cdk from 'aws-cdk-lib'; | ||
|
||
|
||
export interface testprops extends cdk.StackProps { | ||
env: cdk.Environment, | ||
prefix : string; | ||
|
||
} | ||
|
||
export class SqsStack extends Stack { | ||
constructor(scope: Construct, id: string, props: testprops) { | ||
super(scope, id, props); | ||
|
||
|
||
const deadLetterQueue = new sqs.Queue(this, 'DeadLetterQueue',{ | ||
queueName : props.prefix+' my-queue' | ||
}); | ||
} | ||
|
||
|
||
} | ||
|
Oops, something went wrong.