AWS CDK constructs and utilities designed to help shortcut provisioning and deploying AWS infrastructure for Reuters Graphics projects.
Integrates directly and is designed to be used with TR's tr-cdk-lib library.
You'll need to install the Python package cloud-tool to manage your access to Platform Engineering's AWS account. Follow the installation guide here with the help of an editor.
(You may want to follow notes on this issue to setup your system Python, first.)
Once cloud-tool is available on your machine, install our graphics-aws-tools (gat) CLI to manage your AWS access.
You need to install @tr-aws-cdk/cli and tr-cdk-lib from our private registry.
First, globally install aws-cdk:
npm install -g aws-cdk
Login to TR's private registry with the following command:
npm login --registry=https://tr1.jfrog.io/tr1/api/npm/npm/ --always-auth
Install the TR libs:
npm install tr-cdk-lib @tr-aws-cdk/cli --registry=https://tr1.jfrog.io/tr1/api/npm/npm/
Install structs and required peer dependencies:
npm i -D @reuters-graphics/structs esbuild
Create your stack using structs.
// src/myStack.ts
import * as cdk from 'aws-cdk-lib';
import { Construct } from 'constructs';
export class MyCdkStack extends cdk.Stack {
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
// Use structs to create your infrastructure...
}
}
Create your CDK app and use your stack.
// bin/app.ts
import { TRCdk, TRDeploymentEnv } from 'tr-cdk-lib/core/lib';
import { MyCdkStack } from '../src/myStack';
const app = TRCdk.newApp({
assetId: '205245',
resourceOwner: '<your email>@thomsonreuters.com',
awsTargetEnv: {
regions: ['us-east-1'],
},
optionalTRTags: {
financialId: '688111232',
projectName: 'graphics-project',
},
deploymentEnv: TRDeploymentEnv.DEV,
});
const myStack = new MyCdkStack(app, 'project-stack');
Reference your CDK app in CDK's config.
// cdk.json
{
"app": "npx tsx bin/app.ts"
}
Deploy it!
Setup the following deploy scripts in your package.json.
Remember: Before you deploy, you need a valid STS token to access TR's AWS. You can generate a new one using
gat logon. (They last about 8 hours.)
cdk:synthGenerates and outputs the CloudFormation template for your CDK application. This command synthesizes your CDK code into a JSON/YAML CloudFormation template in a cdk.out/ directory, allowing you to see what will be deployed without actually deploying it.
rimraf ./cdk.out && cdk synth --profile tr-reuters-editorial-dataminer-nonprod
cdk:bootstrapSets up the necessary infrastructure in your AWS environment to support deploying CDK apps. This includes things like creating necessary iam roles and an S3 bucket for storing assets like Lambda function code. It's a required step before deploying CDK apps for the first time in a new AWS environment.
NOTE: In the command below, replace <YOUR_TR_EMAIL> with your TR email and <AWS_ACCOUNT_ID> with the account ID found in your tr-reuters-editorial-dataminer-nonprod AWS profile in ~/.aws/credentials.
trcdk bootstrap --profile tr-reuters-editorial-dataminer-nonprod --asset-id 205245 --resource-owner <YOUR_TR_EMAIL> --environment-type DEVELOPMENT --environment-suffix dev aws://<AWS_ACCOUNT_ID>/us-east-1
cdk:deployDeploys the specified stacks in your CDK application to AWS. This command synthesizes your app and then uses the generated CloudFormation templates to create or update AWS resources in your account.
cdk deploy --all --profile tr-reuters-editorial-dataminer-nonprod
cdk:destroyRemoves the specified stacks from your AWS account. This command deletes all the AWS resources defined in the stack, effectively tearing down the infrastructure that was deployed.
cdk destroy --all --profile tr-reuters-editorial-dataminer-nonprod