From a456155470352b9fb969694e7553bcb10ae76656 Mon Sep 17 00:00:00 2001 From: Elad Ben-Israel Date: Fri, 14 Sep 2018 01:41:14 +0300 Subject: [PATCH 01/13] Initial commit --- .../@aws-cdk/aws-certificatemanager/README.md | 2 +- .../aws-cloudwatch/test/test.alarm.ts | 4 +- .../@aws-cdk/aws-ecr/lib/repository-ref.ts | 17 ++-- packages/@aws-cdk/aws-ecr/lib/repository.ts | 8 +- packages/@aws-cdk/aws-events/lib/rule-ref.ts | 9 +- packages/@aws-cdk/aws-events/lib/rule.ts | 4 +- packages/@aws-cdk/aws-events/lib/target.ts | 4 +- .../@aws-cdk/aws-events/test/test.rule.ts | 6 +- packages/@aws-cdk/aws-iam/lib/group.ts | 12 +-- .../@aws-cdk/aws-iam/lib/managed-policy.ts | 4 +- packages/@aws-cdk/aws-iam/lib/policy.ts | 4 +- packages/@aws-cdk/aws-iam/lib/role.ts | 20 ++--- packages/@aws-cdk/aws-iam/lib/user.ts | 18 ++-- .../@aws-cdk/aws-iam/test/integ.policy.ts | 6 +- packages/@aws-cdk/aws-iam/test/integ.role.ts | 6 +- packages/@aws-cdk/aws-iam/test/test.policy.ts | 18 ++-- packages/@aws-cdk/aws-iam/test/test.role.ts | 6 +- packages/@aws-cdk/aws-kms/lib/alias.ts | 6 +- packages/@aws-cdk/aws-kms/lib/key.ts | 12 +-- packages/@aws-cdk/aws-kms/test/integ.key.ts | 2 +- packages/@aws-cdk/aws-kms/test/test.key.ts | 10 +-- .../aws-logs/test/test.subscriptionfilter.ts | 2 +- .../aws-s3-notifications/lib/destination.ts | 4 +- packages/@aws-cdk/aws-s3/lib/bucket.ts | 36 ++++---- .../notifications-resource.ts | 6 +- packages/@aws-cdk/aws-s3/lib/util.ts | 16 ++-- .../aws-s3/test/notification-dests.ts | 8 +- packages/@aws-cdk/aws-s3/test/test.bucket.ts | 8 +- packages/@aws-cdk/aws-s3/test/test.util.ts | 17 ++-- packages/@aws-cdk/aws-sqs/test/test.sqs.ts | 2 +- .../@aws-cdk/cdk/lib/cloudformation/arn.ts | 85 +++++++++++++------ .../cdk/lib/cloudformation/permission.ts | 18 ++-- .../cdk/lib/cloudformation/resource.ts | 7 ++ packages/@aws-cdk/cdk/lib/core/tokens.ts | 31 ++++++- .../cdk/test/cloudformation/test.arn.ts | 26 +++--- .../cdk/test/cloudformation/test.perms.ts | 20 ++--- .../cdk/test/cloudformation/test.resource.ts | 23 +++-- tools/cfn2ts/lib/codegen.ts | 32 ++++--- tools/cfn2ts/lib/genspec.ts | 33 ++++--- 39 files changed, 315 insertions(+), 237 deletions(-) diff --git a/packages/@aws-cdk/aws-certificatemanager/README.md b/packages/@aws-cdk/aws-certificatemanager/README.md index 63e5aee4ba19e..2356395be099d 100644 --- a/packages/@aws-cdk/aws-certificatemanager/README.md +++ b/packages/@aws-cdk/aws-certificatemanager/README.md @@ -41,7 +41,7 @@ Import a certificate either manually, if you know the ARN: ```ts const certificate = Certificate.import(this, 'Certificate', { - certificteArn: new Arn("arn:aws:...") + certificteArn: "arn:aws:..." }); ``` diff --git a/packages/@aws-cdk/aws-cloudwatch/test/test.alarm.ts b/packages/@aws-cdk/aws-cloudwatch/test/test.alarm.ts index 52a9d7dd1238e..669d0e9e0ea4d 100644 --- a/packages/@aws-cdk/aws-cloudwatch/test/test.alarm.ts +++ b/packages/@aws-cdk/aws-cloudwatch/test/test.alarm.ts @@ -109,7 +109,7 @@ class TestAlarmAction implements IAlarmAction { constructor(private readonly arn: string) { } - public get alarmActionArn(): Arn { - return new Arn(this.arn); + public get alarmActionArn(): string { + return this.arn; } } diff --git a/packages/@aws-cdk/aws-ecr/lib/repository-ref.ts b/packages/@aws-cdk/aws-ecr/lib/repository-ref.ts index a63fb0911aceb..8683257096320 100644 --- a/packages/@aws-cdk/aws-ecr/lib/repository-ref.ts +++ b/packages/@aws-cdk/aws-ecr/lib/repository-ref.ts @@ -1,5 +1,4 @@ import cdk = require('@aws-cdk/cdk'); -import { RepositoryArn, RepositoryName } from './ecr.generated'; /** * An ECR repository @@ -15,12 +14,12 @@ export abstract class RepositoryRef extends cdk.Construct { /** * The name of the repository */ - public abstract readonly repositoryName: RepositoryName; + public abstract readonly repositoryName: string; /** * The ARN of the repository */ - public abstract readonly repositoryArn: RepositoryArn; + public abstract readonly repositoryArn: string; /** * Add a policy statement to the repository's resource policy @@ -32,7 +31,7 @@ export abstract class RepositoryRef extends cdk.Construct { */ public export(): RepositoryRefProps { return { - repositoryArn: new RepositoryArn(new cdk.Output(this, 'RepositoryArn', { value: this.repositoryArn }).makeImportValue()), + repositoryArn: new cdk.Output(this, 'RepositoryArn', { value: this.repositoryArn }).makeImportValue().toString(), }; } @@ -41,7 +40,7 @@ export abstract class RepositoryRef extends cdk.Construct { */ public get repositoryUri(): RepositoryUri { // Calculate this from the ARN - const parts = cdk.Arn.parseToken(this.repositoryArn); + const parts = cdk.ArnUtils.parse(this.repositoryArn); return new RepositoryUri(`${parts.account}.dkr.ecr.${parts.region}.amazonaws.com/${parts.resourceName}`); } } @@ -53,20 +52,20 @@ export class RepositoryUri extends cdk.CloudFormationToken { } export interface RepositoryRefProps { - repositoryArn: RepositoryArn; + repositoryArn: string; } /** * An already existing repository */ class ImportedRepository extends RepositoryRef { - public readonly repositoryName: RepositoryName; - public readonly repositoryArn: RepositoryArn; + public readonly repositoryName: string; + public readonly repositoryArn: string; constructor(parent: cdk.Construct, id: string, props: RepositoryRefProps) { super(parent, id); this.repositoryArn = props.repositoryArn; - this.repositoryName = new RepositoryName(cdk.Arn.parseToken(props.repositoryArn).resourceName); + this.repositoryName = cdk.ArnUtils.parse(props.repositoryArn).resourceName!; } public addToResourcePolicy(_statement: cdk.PolicyStatement) { diff --git a/packages/@aws-cdk/aws-ecr/lib/repository.ts b/packages/@aws-cdk/aws-ecr/lib/repository.ts index 1043970e0f052..831ae6bb751a1 100644 --- a/packages/@aws-cdk/aws-ecr/lib/repository.ts +++ b/packages/@aws-cdk/aws-ecr/lib/repository.ts @@ -1,5 +1,5 @@ import cdk = require('@aws-cdk/cdk'); -import { cloudformation, RepositoryArn, RepositoryName } from './ecr.generated'; +import { cloudformation } from './ecr.generated'; import { CountType, LifecycleRule, TagStatus } from './lifecycle'; import { RepositoryRef } from "./repository-ref"; @@ -41,8 +41,8 @@ export interface RepositoryProps { * Define an ECR repository */ export class Repository extends RepositoryRef { - public readonly repositoryName: RepositoryName; - public readonly repositoryArn: RepositoryArn; + public readonly repositoryName: string; + public readonly repositoryArn: string; private readonly lifecycleRules = new Array(); private readonly registryId?: string; private policyDocument?: cdk.PolicyDocument; @@ -66,7 +66,7 @@ export class Repository extends RepositoryRef { props.lifecycleRules.forEach(this.addLifecycleRule.bind(this)); } - this.repositoryName = resource.ref; + this.repositoryName = resource.repositoryName; this.repositoryArn = resource.repositoryArn; } diff --git a/packages/@aws-cdk/aws-events/lib/rule-ref.ts b/packages/@aws-cdk/aws-events/lib/rule-ref.ts index 4a0a8478e562f..6d8d045a3de52 100644 --- a/packages/@aws-cdk/aws-events/lib/rule-ref.ts +++ b/packages/@aws-cdk/aws-events/lib/rule-ref.ts @@ -1,12 +1,11 @@ import { Construct, Output } from '@aws-cdk/cdk'; -import { RuleArn } from './events.generated'; export interface EventRuleRefProps { /** * The value of the event rule Amazon Resource Name (ARN), such as * arn:aws:events:us-east-2:123456789012:rule/example. */ - eventRuleArn: RuleArn; + eventRuleArn: string; } export abstract class EventRuleRef extends Construct { @@ -22,20 +21,20 @@ export abstract class EventRuleRef extends Construct { * The value of the event rule Amazon Resource Name (ARN), such as * arn:aws:events:us-east-2:123456789012:rule/example. */ - public abstract readonly ruleArn: RuleArn; + public abstract readonly ruleArn: string; /** * Exports this rule resource from this stack and returns an import token. */ public export(): EventRuleRefProps { return { - eventRuleArn: new RuleArn(new Output(this, 'RuleArn', { value: this.ruleArn }).makeImportValue()) + eventRuleArn: new Output(this, 'RuleArn', { value: this.ruleArn }).makeImportValue().toString() }; } } class ImportedEventRule extends EventRuleRef { - public readonly ruleArn: RuleArn; + public readonly ruleArn: string; constructor(parent: Construct, name: string, props: EventRuleRefProps) { super(parent, name); diff --git a/packages/@aws-cdk/aws-events/lib/rule.ts b/packages/@aws-cdk/aws-events/lib/rule.ts index 14e1fa20f241a..c17aaacae30c3 100644 --- a/packages/@aws-cdk/aws-events/lib/rule.ts +++ b/packages/@aws-cdk/aws-events/lib/rule.ts @@ -1,6 +1,6 @@ import { Construct, FnConcat, Token } from '@aws-cdk/cdk'; import { EventPattern } from './event-pattern'; -import { cloudformation, RuleArn } from './events.generated'; +import { cloudformation } from './events.generated'; import { TargetInputTemplate } from './input-options'; import { EventRuleRef } from './rule-ref'; import { IEventRuleTarget } from './target'; @@ -64,7 +64,7 @@ export interface EventRuleProps { * Defines a CloudWatch Event Rule in this stack. */ export class EventRule extends EventRuleRef { - public readonly ruleArn: RuleArn; + public readonly ruleArn: string; private readonly targets = new Array(); private readonly eventPattern: EventPattern = { }; diff --git a/packages/@aws-cdk/aws-events/lib/target.ts b/packages/@aws-cdk/aws-events/lib/target.ts index 557abc90a651d..72a14cf005e39 100644 --- a/packages/@aws-cdk/aws-events/lib/target.ts +++ b/packages/@aws-cdk/aws-events/lib/target.ts @@ -1,6 +1,6 @@ import iam = require('@aws-cdk/aws-iam'); import cdk = require('@aws-cdk/cdk'); -import { cloudformation, RuleArn } from './events.generated'; +import { cloudformation } from './events.generated'; export interface EventRuleTargetProps { /** @@ -54,5 +54,5 @@ export interface IEventRuleTarget { * @param ruleArn The ARN of the CloudWatch Event Rule that would trigger this target. * @param ruleUniqueId A unique ID for this rule. Can be used to implement idempotency. */ - asEventRuleTarget(ruleArn: RuleArn, ruleUniqueId: string): EventRuleTargetProps; + asEventRuleTarget(ruleArn: string, ruleUniqueId: string): EventRuleTargetProps; } diff --git a/packages/@aws-cdk/aws-events/test/test.rule.ts b/packages/@aws-cdk/aws-events/test/test.rule.ts index 7ef0d9a0fd19d..e448f26f72810 100644 --- a/packages/@aws-cdk/aws-events/test/test.rule.ts +++ b/packages/@aws-cdk/aws-events/test/test.rule.ts @@ -3,7 +3,7 @@ import iam = require('@aws-cdk/aws-iam'); import cdk = require('@aws-cdk/cdk'); import { resolve } from '@aws-cdk/cdk'; import { Test } from 'nodeunit'; -import { IEventRuleTarget, RuleArn } from '../lib'; +import { IEventRuleTarget } from '../lib'; import { EventRule } from '../lib/rule'; // tslint:disable:object-literal-key-quotes @@ -312,11 +312,11 @@ export = { 'asEventRuleTarget can use the ruleArn and a uniqueId of the rule'(test: Test) { const stack = new cdk.Stack(); - let receivedRuleArn = new RuleArn('FAIL'); + let receivedRuleArn = 'FAIL'; let receivedRuleId = 'FAIL'; const t1: IEventRuleTarget = { - asEventRuleTarget: (ruleArn: RuleArn, ruleId: string) => { + asEventRuleTarget: (ruleArn: string, ruleId: string) => { receivedRuleArn = ruleArn; receivedRuleId = ruleId; diff --git a/packages/@aws-cdk/aws-iam/lib/group.ts b/packages/@aws-cdk/aws-iam/lib/group.ts index 7861c3bae2561..3f17486227f04 100644 --- a/packages/@aws-cdk/aws-iam/lib/group.ts +++ b/packages/@aws-cdk/aws-iam/lib/group.ts @@ -1,5 +1,5 @@ -import { Arn, ArnPrincipal, Construct, PolicyPrincipal, PolicyStatement } from '@aws-cdk/cdk'; -import { cloudformation, GroupArn, GroupName } from './iam.generated'; +import { ArnPrincipal, Construct, PolicyPrincipal, PolicyStatement } from '@aws-cdk/cdk'; +import { cloudformation } from './iam.generated'; import { IIdentityResource, IPrincipal, Policy } from './policy'; import { User } from './user'; import { AttachedPolicies, undefinedIfEmpty } from './util'; @@ -37,12 +37,12 @@ export class Group extends Construct implements IIdentityResource, IPrincipal { /** * The runtime name of this group. */ - public readonly groupName: GroupName; + public readonly groupName: string; /** * The ARN of this group. */ - public readonly groupArn: GroupArn; + public readonly groupArn: string; /** * An "AWS" policy principal that represents this group. @@ -64,7 +64,7 @@ export class Group extends Construct implements IIdentityResource, IPrincipal { path: props.path, }); - this.groupName = group.ref; + this.groupName = group.groupName; this.groupArn = group.groupArn; this.principal = new ArnPrincipal(this.groupArn); } @@ -73,7 +73,7 @@ export class Group extends Construct implements IIdentityResource, IPrincipal { * Attaches a managed policy to this group. * @param arn The ARN of the managed policy to attach. */ - public attachManagedPolicy(arn: Arn) { + public attachManagedPolicy(arn: string) { this.managedPolicies.push(arn); } diff --git a/packages/@aws-cdk/aws-iam/lib/managed-policy.ts b/packages/@aws-cdk/aws-iam/lib/managed-policy.ts index 41d6e762b560e..fe0b6b15a691c 100644 --- a/packages/@aws-cdk/aws-iam/lib/managed-policy.ts +++ b/packages/@aws-cdk/aws-iam/lib/managed-policy.ts @@ -16,9 +16,9 @@ export class AwsManagedPolicy { /** * The Arn of this managed policy */ - public get policyArn(): cdk.Arn { + public get policyArn(): string { // the arn is in the form of - arn:aws:iam::aws:policy/ - return cdk.Arn.fromComponents({ + return cdk.ArnUtils.fromComponents({ service: "iam", region: "", // no region for managed policy account: "aws", // the account for a managed policy is 'aws' diff --git a/packages/@aws-cdk/aws-iam/lib/policy.ts b/packages/@aws-cdk/aws-iam/lib/policy.ts index 7dfe6f0c92e07..5c2c2a5e08f46 100644 --- a/packages/@aws-cdk/aws-iam/lib/policy.ts +++ b/packages/@aws-cdk/aws-iam/lib/policy.ts @@ -1,4 +1,4 @@ -import { Arn, Construct, IDependable, PolicyDocument, PolicyPrincipal, PolicyStatement, Token } from '@aws-cdk/cdk'; +import { Construct, IDependable, PolicyDocument, PolicyPrincipal, PolicyStatement, Token } from '@aws-cdk/cdk'; import { Group } from './group'; import { cloudformation } from './iam.generated'; import { Role } from './role'; @@ -31,7 +31,7 @@ export interface IPrincipal { * Attaches a managed policy to this principal. * @param arn The ARN of the managed policy */ - attachManagedPolicy(arn: Arn): void; + attachManagedPolicy(arn: string): void; } /** diff --git a/packages/@aws-cdk/aws-iam/lib/role.ts b/packages/@aws-cdk/aws-iam/lib/role.ts index 21377e33bb99a..785c0ebb76c17 100644 --- a/packages/@aws-cdk/aws-iam/lib/role.ts +++ b/packages/@aws-cdk/aws-iam/lib/role.ts @@ -1,5 +1,5 @@ -import { Arn, ArnPrincipal, Construct, IDependable, PolicyDocument, PolicyPrincipal, PolicyStatement } from '@aws-cdk/cdk'; -import { cloudformation, RoleArn, RoleName } from './iam.generated'; +import { ArnPrincipal, Construct, IDependable, PolicyDocument, PolicyPrincipal, PolicyStatement } from '@aws-cdk/cdk'; +import { cloudformation } from './iam.generated'; import { IIdentityResource, IPrincipal, Policy } from './policy'; import { AttachedPolicies, undefinedIfEmpty } from './util'; @@ -79,12 +79,12 @@ export class Role extends Construct implements IIdentityResource, IPrincipal, ID /** * Returns the ARN of this role. */ - public readonly roleArn: RoleArn; + public readonly roleArn: string; /** * Returns the name of the role. */ - public readonly roleName: RoleName; + public readonly roleName: string; /** * Returns the ARN of this role. @@ -97,20 +97,20 @@ export class Role extends Construct implements IIdentityResource, IPrincipal, ID public readonly dependencyElements: IDependable[]; private defaultPolicy?: Policy; - private readonly managedPolicies: Arn[]; + private readonly managedPolicieArns: string[]; private readonly attachedPolicies = new AttachedPolicies(); constructor(parent: Construct, name: string, props: RoleProps) { super(parent, name); this.assumeRolePolicy = createAssumeRolePolicy(props.assumedBy); - this.managedPolicies = props.managedPolicyArns || [ ]; + this.managedPolicieArns = props.managedPolicyArns || [ ]; validateMaxSessionDuration(props.maxSessionDurationSec); const role = new cloudformation.RoleResource(this, 'Resource', { assumeRolePolicyDocument: this.assumeRolePolicy as any, - managedPolicyArns: undefinedIfEmpty(() => this.managedPolicies), + managedPolicyArns: undefinedIfEmpty(() => this.managedPolicieArns), path: props.path, roleName: props.roleName, maxSessionDuration: props.maxSessionDurationSec @@ -118,7 +118,7 @@ export class Role extends Construct implements IIdentityResource, IPrincipal, ID this.roleArn = role.roleArn; this.principal = new ArnPrincipal(this.roleArn); - this.roleName = role.ref; + this.roleName = role.roleName; this.dependencyElements = [ role ]; } @@ -140,8 +140,8 @@ export class Role extends Construct implements IIdentityResource, IPrincipal, ID * Attaches a managed policy to this role. * @param arn The ARN of the managed policy to attach. */ - public attachManagedPolicy(arn: Arn) { - this.managedPolicies.push(arn); + public attachManagedPolicy(arn: string) { + this.managedPolicieArns.push(arn); } /** diff --git a/packages/@aws-cdk/aws-iam/lib/user.ts b/packages/@aws-cdk/aws-iam/lib/user.ts index 6393a1cca6f8c..9986d73fe937d 100644 --- a/packages/@aws-cdk/aws-iam/lib/user.ts +++ b/packages/@aws-cdk/aws-iam/lib/user.ts @@ -1,6 +1,6 @@ -import { Arn, ArnPrincipal, Construct, PolicyPrincipal, PolicyStatement } from '@aws-cdk/cdk'; +import { ArnPrincipal, Construct, PolicyPrincipal, PolicyStatement } from '@aws-cdk/cdk'; import { Group } from './group'; -import { cloudformation, UserArn, UserName } from './iam.generated'; +import { cloudformation } from './iam.generated'; import { IIdentityResource, IPrincipal, Policy } from './policy'; import { AttachedPolicies, undefinedIfEmpty } from './util'; @@ -66,12 +66,12 @@ export class User extends Construct implements IIdentityResource, IPrincipal { /** * An attribute that represents the user name. */ - public readonly userName: UserName; + public readonly userName: string; /** * An attribute that represents the user's ARN. */ - public readonly userArn: UserArn; + public readonly userArn: string; /** * Returns the ARN of this user. @@ -79,7 +79,7 @@ export class User extends Construct implements IIdentityResource, IPrincipal { public readonly principal: PolicyPrincipal; private readonly groups = new Array(); - private readonly managedPolicies = new Array(); + private readonly managedPolicyArns = new Array(); private readonly attachedPolicies = new AttachedPolicies(); private defaultPolicy?: Policy; @@ -89,12 +89,12 @@ export class User extends Construct implements IIdentityResource, IPrincipal { const user = new cloudformation.UserResource(this, 'Resource', { userName: props.userName, groups: undefinedIfEmpty(() => this.groups), - managedPolicyArns: undefinedIfEmpty(() => this.managedPolicies), + managedPolicyArns: undefinedIfEmpty(() => this.managedPolicyArns), path: props.path, loginProfile: this.parseLoginProfile(props) }); - this.userName = user.ref; + this.userName = user.userName; this.userArn = user.userArn; this.principal = new ArnPrincipal(this.userArn); @@ -114,8 +114,8 @@ export class User extends Construct implements IIdentityResource, IPrincipal { * Attaches a managed policy to the user. * @param arn The ARN of the managed policy to attach. */ - public attachManagedPolicy(arn: Arn) { - this.managedPolicies.push(arn); + public attachManagedPolicy(arn: string) { + this.managedPolicyArns.push(arn); } /** diff --git a/packages/@aws-cdk/aws-iam/test/integ.policy.ts b/packages/@aws-cdk/aws-iam/test/integ.policy.ts index e54c1b4bcb770..446c5394484b4 100644 --- a/packages/@aws-cdk/aws-iam/test/integ.policy.ts +++ b/packages/@aws-cdk/aws-iam/test/integ.policy.ts @@ -1,4 +1,4 @@ -import { App, Arn, PolicyStatement, Stack } from "@aws-cdk/cdk"; +import { App, PolicyStatement, Stack } from "@aws-cdk/cdk"; import { Policy } from "../lib"; import { User } from "../lib/user"; @@ -9,11 +9,11 @@ const stack = new Stack(app, 'aws-cdk-iam-policy'); const user = new User(stack, 'MyUser'); const policy = new Policy(stack, 'HelloPolicy', { policyName: 'Default' }); -policy.addStatement(new PolicyStatement().addResource(new Arn('*')).addAction('sqs:SendMessage')); +policy.addStatement(new PolicyStatement().addResource('*').addAction('sqs:SendMessage')); policy.attachToUser(user); const policy2 = new Policy(stack, 'GoodbyePolicy'); -policy2.addStatement(new PolicyStatement().addResource(new Arn('*')).addAction('lambda:InvokeFunction')); +policy2.addStatement(new PolicyStatement().addResource('*').addAction('lambda:InvokeFunction')); policy2.attachToUser(user); process.stdout.write(app.run()); diff --git a/packages/@aws-cdk/aws-iam/test/integ.role.ts b/packages/@aws-cdk/aws-iam/test/integ.role.ts index 56a5d1a358244..244ebb12d5fa2 100644 --- a/packages/@aws-cdk/aws-iam/test/integ.role.ts +++ b/packages/@aws-cdk/aws-iam/test/integ.role.ts @@ -1,4 +1,4 @@ -import { App, Arn, PolicyStatement, ServicePrincipal, Stack } from "@aws-cdk/cdk"; +import { App, PolicyStatement, ServicePrincipal, Stack } from "@aws-cdk/cdk"; import { Policy, Role } from "../lib"; const app = new App(process.argv); @@ -9,10 +9,10 @@ const role = new Role(stack, 'TestRole', { assumedBy: new ServicePrincipal('sqs.amazonaws.com') }); -role.addToPolicy(new PolicyStatement().addResource(new Arn('*')).addAction('sqs:SendMessage')); +role.addToPolicy(new PolicyStatement().addResource('*').addAction('sqs:SendMessage')); const policy = new Policy(stack, 'HelloPolicy', { policyName: 'Default' }); -policy.addStatement(new PolicyStatement().addAction('ec2:*').addResource(new Arn('*'))); +policy.addStatement(new PolicyStatement().addAction('ec2:*').addResource('*')); policy.attachToRole(role); process.stdout.write(app.run()); diff --git a/packages/@aws-cdk/aws-iam/test/test.policy.ts b/packages/@aws-cdk/aws-iam/test/test.policy.ts index 4bf419d44cb80..e1eb8ee37c87e 100644 --- a/packages/@aws-cdk/aws-iam/test/test.policy.ts +++ b/packages/@aws-cdk/aws-iam/test/test.policy.ts @@ -1,4 +1,4 @@ -import { App, Arn, PolicyStatement, ServicePrincipal, Stack } from '@aws-cdk/cdk'; +import { App, PolicyStatement, ServicePrincipal, Stack } from '@aws-cdk/cdk'; import { Test } from 'nodeunit'; import { Role } from '../lib'; import { Group } from '../lib/group'; @@ -21,8 +21,8 @@ export = { const stack = new Stack(app, 'MyStack'); const policy = new Policy(stack, 'MyPolicy', { policyName: 'MyPolicyName' }); - policy.addStatement(new PolicyStatement().addResource(new Arn('*')).addAction('sqs:SendMessage')); - policy.addStatement(new PolicyStatement().addResource(new Arn('arn')).addAction('sns:Subscribe')); + policy.addStatement(new PolicyStatement().addResource('*').addAction('sqs:SendMessage')); + policy.addStatement(new PolicyStatement().addResource('arn').addAction('sns:Subscribe')); const group = new Group(stack, 'MyGroup'); group.attachInlinePolicy(policy); @@ -47,8 +47,8 @@ export = { const stack = new Stack(app, 'MyStack'); const policy = new Policy(stack, 'MyPolicy'); - policy.addStatement(new PolicyStatement().addResource(new Arn('*')).addAction('sqs:SendMessage')); - policy.addStatement(new PolicyStatement().addResource(new Arn('arn')).addAction('sns:Subscribe')); + policy.addStatement(new PolicyStatement().addResource('*').addAction('sqs:SendMessage')); + policy.addStatement(new PolicyStatement().addResource('arn').addAction('sns:Subscribe')); const user = new User(stack, 'MyUser'); user.attachInlinePolicy(policy); @@ -84,7 +84,7 @@ export = { users: [ user1 ], groups: [ group1 ], roles: [ role1 ], - statements: [ new PolicyStatement().addResource(new Arn('*')).addAction('dynamodb:PutItem') ], + statements: [ new PolicyStatement().addResource('*').addAction('dynamodb:PutItem') ], }); test.deepEqual(app.synthesizeStack(stack.name).template, { Resources: @@ -118,7 +118,7 @@ export = { const app = new App(); const stack = new Stack(app, 'MyStack'); const p = new Policy(stack, 'MyPolicy'); - p.addStatement(new PolicyStatement().addAction('*').addResource(new Arn('*'))); + p.addStatement(new PolicyStatement().addAction('*').addResource('*')); const user = new User(stack, 'MyUser'); p.attachToUser(user); @@ -150,7 +150,7 @@ export = { p.attachToUser(new User(stack, 'User2')); p.attachToGroup(new Group(stack, 'Group1')); p.attachToRole(new Role(stack, 'Role1', { assumedBy: new ServicePrincipal('lambda.amazonaws.com') })); - p.addStatement(new PolicyStatement().addResource(new Arn('*')).addAction('dynamodb:GetItem')); + p.addStatement(new PolicyStatement().addResource('*').addAction('dynamodb:GetItem')); test.deepEqual(app.synthesizeStack(stack.name).template, { Resources: { MyTestPolicy316BDB50: @@ -192,7 +192,7 @@ export = { group.attachInlinePolicy(policy); role.attachInlinePolicy(policy); - policy.addStatement(new PolicyStatement().addResource(new Arn('*')).addAction('*')); + policy.addStatement(new PolicyStatement().addResource('*').addAction('*')); test.deepEqual(app.synthesizeStack(stack.name).template, { Resources: { MyPolicy39D66CF6: diff --git a/packages/@aws-cdk/aws-iam/test/test.role.ts b/packages/@aws-cdk/aws-iam/test/test.role.ts index cb5c88a58335a..98876bdf8d2a2 100644 --- a/packages/@aws-cdk/aws-iam/test/test.role.ts +++ b/packages/@aws-cdk/aws-iam/test/test.role.ts @@ -1,5 +1,5 @@ import { expect, haveResource } from '@aws-cdk/assert'; -import { Arn, FederatedPrincipal, PolicyStatement, Resource, ServicePrincipal, Stack } from '@aws-cdk/cdk'; +import { FederatedPrincipal, PolicyStatement, Resource, ServicePrincipal, Stack } from '@aws-cdk/cdk'; import { Test } from 'nodeunit'; import { Role } from '../lib'; @@ -33,7 +33,7 @@ export = { test.ok(!('MyRoleDefaultPolicyA36BE1DD' in stack.toCloudFormation().Resources), 'initially created without a policy'); - role.addToPolicy(new PolicyStatement().addResource(new Arn('myresource')).addAction('myaction')); + role.addToPolicy(new PolicyStatement().addResource('myresource').addAction('myaction')); test.ok(stack.toCloudFormation().Resources.MyRoleDefaultPolicyA36BE1DD, 'policy resource created'); expect(stack).toMatch({ Resources: @@ -66,7 +66,7 @@ export = { managedPolicyArns: [ 'managed1', 'managed2' ] }); - role.attachManagedPolicy(new Arn('managed3')); + role.attachManagedPolicy('managed3'); expect(stack).toMatch({ Resources: { MyRoleF48FFE04: { Type: 'AWS::IAM::Role', diff --git a/packages/@aws-cdk/aws-kms/lib/alias.ts b/packages/@aws-cdk/aws-kms/lib/alias.ts index fac0514430288..c65c957ebb61e 100644 --- a/packages/@aws-cdk/aws-kms/lib/alias.ts +++ b/packages/@aws-cdk/aws-kms/lib/alias.ts @@ -1,6 +1,6 @@ import { Construct } from '@aws-cdk/cdk'; import { EncryptionKeyRef } from './key'; -import { AliasName, cloudformation } from './kms.generated'; +import { cloudformation } from './kms.generated'; const REQUIRED_ALIAS_PREFIX = 'alias/'; const DISALLOWED_PREFIX = REQUIRED_ALIAS_PREFIX + 'AWS'; @@ -34,7 +34,7 @@ export class EncryptionKeyAlias extends Construct { /** * The name of the alias. */ - public aliasName: AliasName; + public aliasName: string; constructor(parent: Construct, name: string, props: EncryptionKeyAliasProps) { super(parent, name); @@ -56,6 +56,6 @@ export class EncryptionKeyAlias extends Construct { targetKeyId: props.key.keyArn }); - this.aliasName = resource.ref; + this.aliasName = resource.aliasName; } } diff --git a/packages/@aws-cdk/aws-kms/lib/key.ts b/packages/@aws-cdk/aws-kms/lib/key.ts index c73bc7e1afe18..6b474e7118da1 100644 --- a/packages/@aws-cdk/aws-kms/lib/key.ts +++ b/packages/@aws-cdk/aws-kms/lib/key.ts @@ -1,12 +1,12 @@ import { Construct, DeletionPolicy, Output, PolicyDocument, PolicyStatement, resolve } from '@aws-cdk/cdk'; import { EncryptionKeyAlias } from './alias'; -import { cloudformation, KeyArn } from './kms.generated'; +import { cloudformation } from './kms.generated'; export interface EncryptionKeyRefProps { /** * The ARN of the external KMS key. */ - keyArn: KeyArn; + keyArn: string; } export abstract class EncryptionKeyRef extends Construct { @@ -35,7 +35,7 @@ export abstract class EncryptionKeyRef extends Construct { /** * The ARN of the key. */ - public abstract readonly keyArn: KeyArn; + public abstract readonly keyArn: string; /** * Optional policy document that represents the resource policy of this key. @@ -74,7 +74,7 @@ export abstract class EncryptionKeyRef extends Construct { */ public export(): EncryptionKeyRefProps { return { - keyArn: new KeyArn(new Output(this, 'KeyArn').makeImportValue()) + keyArn: new Output(this, 'KeyArn').makeImportValue().toString() }; } } @@ -114,7 +114,7 @@ export interface EncryptionKeyProps { * Definews a KMS key. */ export class EncryptionKey extends EncryptionKeyRef { - public readonly keyArn: KeyArn; + public readonly keyArn: string; protected readonly policy?: PolicyDocument; constructor(parent: Construct, name: string, props: EncryptionKeyProps = {}) { @@ -166,7 +166,7 @@ export class EncryptionKey extends EncryptionKeyRef { } class EncryptionKeyRefImport extends EncryptionKeyRef { - public readonly keyArn: KeyArn; + public readonly keyArn: string; protected readonly policy = undefined; // no policy associated with an imported key constructor(parent: Construct, name: string, props: EncryptionKeyRefProps) { diff --git a/packages/@aws-cdk/aws-kms/test/integ.key.ts b/packages/@aws-cdk/aws-kms/test/integ.key.ts index 48c27231d6d91..17a310d492285 100644 --- a/packages/@aws-cdk/aws-kms/test/integ.key.ts +++ b/packages/@aws-cdk/aws-kms/test/integ.key.ts @@ -10,7 +10,7 @@ const key = new EncryptionKey(stack, 'MyKey'); key.addToResourcePolicy(new PolicyStatement() .addAllResources() .addAction('kms:encrypt') - .addAwsPrincipal(new Arn(new AwsAccountId()))); + .addAwsPrincipal(new AwsAccountId().toString())); key.addAlias('alias/bar'); diff --git a/packages/@aws-cdk/aws-kms/test/test.key.ts b/packages/@aws-cdk/aws-kms/test/test.key.ts index 08ee93a880b18..492560b2e4c18 100644 --- a/packages/@aws-cdk/aws-kms/test/test.key.ts +++ b/packages/@aws-cdk/aws-kms/test/test.key.ts @@ -1,7 +1,7 @@ import { exactlyMatchTemplate, expect } from '@aws-cdk/assert'; import { App, Arn, PolicyDocument, PolicyStatement, Stack } from '@aws-cdk/cdk'; import { Test } from 'nodeunit'; -import { EncryptionKey, KeyArn } from '../lib'; +import { EncryptionKey } from '../lib'; export = { 'default key'(test: Test) { @@ -70,7 +70,7 @@ export = { const key = new EncryptionKey(stack, 'MyKey'); const p = new PolicyStatement().addAllResources().addAction('kms:encrypt'); - p.addAwsPrincipal(new Arn('arn')); + p.addAwsPrincipal('arn'); key.addToResourcePolicy(p); expect(app.synthesizeStack(stack.name)).to(exactlyMatchTemplate({ @@ -145,7 +145,7 @@ export = { enabled: false }); const p = new PolicyStatement().addAllResources().addAction('kms:encrypt'); - p.addAwsPrincipal(new Arn('arn')); + p.addAwsPrincipal('arn'); key.addToResourcePolicy(p); expect(app.synthesizeStack(stack.name)).to(exactlyMatchTemplate({ @@ -355,7 +355,7 @@ export = { 'succeed if set to true (default)'(test: Test) { const stack = new Stack(); - const key = EncryptionKey.import(stack, 'Imported', { keyArn: new KeyArn('foo/bar') }); + const key = EncryptionKey.import(stack, 'Imported', { keyArn: 'foo/bar' }); key.addToResourcePolicy(new PolicyStatement().addAllResources().addAction('*')); @@ -366,7 +366,7 @@ export = { const stack = new Stack(); - const key = EncryptionKey.import(stack, 'Imported', { keyArn: new KeyArn('foo/bar') }); + const key = EncryptionKey.import(stack, 'Imported', { keyArn: 'foo/bar' }); test.throws(() => key.addToResourcePolicy(new PolicyStatement().addAllResources().addAction('*'), /* allowNoOp */ false), diff --git a/packages/@aws-cdk/aws-logs/test/test.subscriptionfilter.ts b/packages/@aws-cdk/aws-logs/test/test.subscriptionfilter.ts index 607425d03ef2c..e54c6acd52a44 100644 --- a/packages/@aws-cdk/aws-logs/test/test.subscriptionfilter.ts +++ b/packages/@aws-cdk/aws-logs/test/test.subscriptionfilter.ts @@ -30,7 +30,7 @@ export = { class FakeDestination implements ILogSubscriptionDestination { public logSubscriptionDestination(_sourceLogGroup: LogGroupRef) { return { - arn: new Arn('arn:bogus'), + arn: 'arn:bogus', }; } } diff --git a/packages/@aws-cdk/aws-s3-notifications/lib/destination.ts b/packages/@aws-cdk/aws-s3-notifications/lib/destination.ts index 286aa4a80e56d..d73f973f22429 100644 --- a/packages/@aws-cdk/aws-s3-notifications/lib/destination.ts +++ b/packages/@aws-cdk/aws-s3-notifications/lib/destination.ts @@ -12,7 +12,7 @@ export interface IBucketNotificationDestination { * @param bucketArn The ARN of the bucket * @param bucketId A unique ID of this bucket in the stack */ - asBucketNotificationDestination(bucketArn: cdk.Arn, bucketId: string): BucketNotificationDestinationProps; + asBucketNotificationDestination(bucketArn: string, bucketId: string): BucketNotificationDestinationProps; } /** @@ -27,7 +27,7 @@ export interface BucketNotificationDestinationProps { /** * The ARN of the destination (i.e. Lambda, SNS, SQS). */ - arn: cdk.Arn; + arn: string; /** * Any additional dependencies that should be resolved before the bucket notification diff --git a/packages/@aws-cdk/aws-s3/lib/bucket.ts b/packages/@aws-cdk/aws-s3/lib/bucket.ts index 48bb6651ff19a..539961830fe06 100644 --- a/packages/@aws-cdk/aws-s3/lib/bucket.ts +++ b/packages/@aws-cdk/aws-s3/lib/bucket.ts @@ -8,7 +8,7 @@ import { BucketNotifications } from './notifications-resource'; import perms = require('./perms'); import { CommonPipelineSourceProps, PipelineSource } from './pipeline-action'; import { LifecycleRule } from './rule'; -import { BucketArn, BucketDomainName, BucketDualStackDomainName, BucketName, cloudformation } from './s3.generated'; +import { cloudformation } from './s3.generated'; import { parseBucketArn, parseBucketName } from './util'; /** @@ -21,7 +21,7 @@ export interface BucketRefProps { * The ARN fo the bucket. At least one of bucketArn or bucketName must be * defined in order to initialize a bucket ref. */ - bucketArn?: BucketArn; + bucketArn?: string; /** * The name of the bucket. If the underlying value of ARN is a string, the @@ -29,7 +29,7 @@ export interface BucketRefProps { * some features that require the bucket name such as auto-creating a bucket * policy, won't work. */ - bucketName?: BucketName; + bucketName?: string; } /** @@ -65,12 +65,12 @@ export abstract class BucketRef extends cdk.Construct { /** * The ARN of the bucket. */ - public abstract readonly bucketArn: BucketArn; + public abstract readonly bucketArn: string; /** * The name of the bucket. */ - public abstract readonly bucketName: BucketName; + public abstract readonly bucketName: string; /** * Optional KMS encryption key associated with this bucket. @@ -96,8 +96,8 @@ export abstract class BucketRef extends cdk.Construct { */ public export(): BucketRefProps { return { - bucketArn: new BucketArn(new cdk.Output(this, 'BucketArn', { value: this.bucketArn }).makeImportValue()), - bucketName: new BucketName(new cdk.Output(this, 'BucketName', { value: this.bucketName }).makeImportValue()), + bucketArn: new cdk.Output(this, 'BucketArn', { value: this.bucketArn }).makeImportValue().toString(), + bucketName: new cdk.Output(this, 'BucketName', { value: this.bucketName }).makeImportValue().toString(), }; } @@ -175,8 +175,8 @@ export abstract class BucketRef extends cdk.Construct { * arnForObjects('home/', team, '/', user, '/*') * */ - public arnForObjects(...keyPattern: any[]): cdk.Arn { - return new cdk.Arn(new cdk.FnConcat(this.bucketArn, '/', ...keyPattern)); + public arnForObjects(...keyPattern: any[]): string { + return new cdk.FnConcat(this.bucketArn, '/', ...keyPattern).toString(); } /** @@ -259,13 +259,13 @@ export abstract class BucketRef extends cdk.Construct { private grant(identity: iam.IPrincipal | undefined, bucketActions: string[], keyActions: string[], - resource: cdk.Arn, ...otherResources: cdk.Arn[]) { + resourceArn: string, ...otherResourceArns: string[]) { if (!identity) { return; } - const resources = [ resource, ...otherResources ]; + const resources = [ resourceArn, ...otherResourceArns ]; identity.addToPolicy(new cdk.PolicyStatement() .addResources(...resources) @@ -353,10 +353,10 @@ export interface BucketProps { * BucketResource. */ export class Bucket extends BucketRef { - public readonly bucketArn: BucketArn; - public readonly bucketName: BucketName; - public readonly domainName: BucketDomainName; - public readonly dualstackDomainName: BucketDualStackDomainName; + public readonly bucketArn: string; + public readonly bucketName: string; + public readonly domainName: string; + public readonly dualstackDomainName: string; public readonly encryptionKey?: kms.EncryptionKeyRef; protected policy?: BucketPolicy; protected autoCreatePolicy = true; @@ -382,7 +382,7 @@ export class Bucket extends BucketRef { this.policy = props.policy; this.encryptionKey = encryptionKey; this.bucketArn = resource.bucketArn; - this.bucketName = resource.ref; + this.bucketName = resource.bucketName; this.domainName = resource.bucketDomainName; this.dualstackDomainName = resource.bucketDualStackDomainName; @@ -722,8 +722,8 @@ export interface NotificationKeyFilter { } class ImportedBucketRef extends BucketRef { - public readonly bucketArn: BucketArn; - public readonly bucketName: BucketName; + public readonly bucketArn: string; + public readonly bucketName: string; public readonly encryptionKey?: kms.EncryptionKey; protected policy?: BucketPolicy; diff --git a/packages/@aws-cdk/aws-s3/lib/notifications-resource/notifications-resource.ts b/packages/@aws-cdk/aws-s3/lib/notifications-resource/notifications-resource.ts index fd26e13a71044..25df0afcf4ae4 100644 --- a/packages/@aws-cdk/aws-s3/lib/notifications-resource/notifications-resource.ts +++ b/packages/@aws-cdk/aws-s3/lib/notifications-resource/notifications-resource.ts @@ -157,15 +157,15 @@ interface CommonConfiguration { } interface LambdaFunctionConfiguration extends CommonConfiguration { - LambdaFunctionArn: cdk.Arn; + LambdaFunctionArn: string; } interface QueueConfiguration extends CommonConfiguration { - QueueArn: cdk.Arn; + QueueArn: string; } interface TopicConfiguration extends CommonConfiguration { - TopicArn: cdk.Arn; + TopicArn: string; } interface FilterRule { diff --git a/packages/@aws-cdk/aws-s3/lib/util.ts b/packages/@aws-cdk/aws-s3/lib/util.ts index a733a7ce7b5ab..0979517900eb1 100644 --- a/packages/@aws-cdk/aws-s3/lib/util.ts +++ b/packages/@aws-cdk/aws-s3/lib/util.ts @@ -1,8 +1,7 @@ -import { Arn } from '@aws-cdk/cdk'; +import cdk = require('@aws-cdk/cdk'); import { BucketRefProps } from './bucket'; -import { BucketArn, BucketName } from './s3.generated'; -export function parseBucketArn(props: BucketRefProps): BucketArn { +export function parseBucketArn(props: BucketRefProps): string { // if we have an explicit bucket ARN, use it. if (props.bucketArn) { @@ -10,20 +9,20 @@ export function parseBucketArn(props: BucketRefProps): BucketArn { } if (props.bucketName) { - return new BucketArn(Arn.fromComponents({ + return cdk.ArnUtils.format({ // S3 Bucket names are globally unique in a partition, // and so their ARNs have empty region and account components region: '', account: '', service: 's3', resource: props.bucketName - })); + }); } throw new Error('Cannot determine bucket ARN. At least `bucketArn` or `bucketName` is needed'); } -export function parseBucketName(props: BucketRefProps): BucketName | undefined { +export function parseBucketName(props: BucketRefProps): string | undefined { // if we have an explicit bucket name, use it. if (props.bucketName) { @@ -32,9 +31,10 @@ export function parseBucketName(props: BucketRefProps): BucketName | undefined { // if we have a string arn, we can extract the bucket name from it. if (props.bucketArn) { - const resolved = props.bucketArn.resolve(); + + const resolved = cdk.resolve(props.bucketArn); if (typeof(resolved) === 'string') { - const components = Arn.parse(resolved); + const components = cdk.ArnUtils.parse(resolved); if (components.service !== 's3') { throw new Error('Invalid ARN. Expecting "s3" service:' + resolved); } diff --git a/packages/@aws-cdk/aws-s3/test/notification-dests.ts b/packages/@aws-cdk/aws-s3/test/notification-dests.ts index d25776297b5d1..02cc6836b7074 100644 --- a/packages/@aws-cdk/aws-s3/test/notification-dests.ts +++ b/packages/@aws-cdk/aws-s3/test/notification-dests.ts @@ -6,7 +6,7 @@ import cdk = require('@aws-cdk/cdk'); * for AWS::SNS::Topic which implements IBucketNotificationDestination. */ export class Topic extends cdk.Construct implements s3notifications.IBucketNotificationDestination { - public readonly topicArn: cdk.Arn; + public readonly topicArn: string; private readonly policy = new cdk.PolicyDocument(); private readonly notifyingBucketPaths = new Set(); @@ -14,7 +14,7 @@ export class Topic extends cdk.Construct implements s3notifications.IBucketNotif super(parent, id); const resource = new cdk.Resource(this, 'Resource', { type: 'AWS::SNS::Topic' }); - const topicArn = new cdk.Ref(resource); + const topicArn = resource.ref; new cdk.Resource(this, 'Policy', { type: 'AWS::SNS::TopicPolicy', @@ -24,10 +24,10 @@ export class Topic extends cdk.Construct implements s3notifications.IBucketNotif } }); - this.topicArn = new cdk.Arn(topicArn); + this.topicArn = topicArn.toString(); } - public asBucketNotificationDestination(bucketArn: cdk.Arn, bucketId: string): s3notifications.BucketNotificationDestinationProps { + public asBucketNotificationDestination(bucketArn: string, bucketId: string): s3notifications.BucketNotificationDestinationProps { // add permission to each source bucket if (!this.notifyingBucketPaths.has(bucketId)) { diff --git a/packages/@aws-cdk/aws-s3/test/test.bucket.ts b/packages/@aws-cdk/aws-s3/test/test.bucket.ts index 9dd939d9de217..acab5f2245479 100644 --- a/packages/@aws-cdk/aws-s3/test/test.bucket.ts +++ b/packages/@aws-cdk/aws-s3/test/test.bucket.ts @@ -203,7 +203,7 @@ export = { const stack = new cdk.Stack(); const bucket = new s3.Bucket(stack, 'MyBucket', { encryption: s3.BucketEncryption.Unencrypted }); - bucket.addToResourcePolicy(new cdk.PolicyStatement().addResource(new cdk.Arn('foo')).addAction('bar')); + bucket.addToResourcePolicy(new cdk.PolicyStatement().addResource('foo').addAction('bar')); expect(stack).toMatch({ "Resources": { @@ -348,11 +348,11 @@ export = { 'static import(ref) allows importing an external/existing bucket'(test: Test) { const stack = new cdk.Stack(); - const bucketArn = new s3.BucketArn('arn:aws:s3:::my-bucket'); + const bucketArn = 'arn:aws:s3:::my-bucket'; const bucket = s3.Bucket.import(stack, 'ImportedBucket', { bucketArn }); // this is a no-op since the bucket is external - bucket.addToResourcePolicy(new cdk.PolicyStatement().addResource(new cdk.Arn('foo')).addAction('bar')); + bucket.addToResourcePolicy(new cdk.PolicyStatement().addResource('foo').addAction('bar')); const p = new cdk.PolicyStatement().addResource(bucket.bucketArn).addAction('s3:ListBucket'); @@ -372,7 +372,7 @@ export = { 'import can also be used to import arbitrary ARNs'(test: Test) { const stack = new cdk.Stack(); - const bucket = s3.Bucket.import(stack, 'ImportedBucket', { bucketArn: new s3.BucketArn('arn:aws:s3:::my-bucket') }); + const bucket = s3.Bucket.import(stack, 'ImportedBucket', { bucketArn: 'arn:aws:s3:::my-bucket' }); bucket.addToResourcePolicy(new cdk.PolicyStatement().addAllResources().addAction('*')); // at this point we technically didn't create any resources in the consuming stack. diff --git a/packages/@aws-cdk/aws-s3/test/test.util.ts b/packages/@aws-cdk/aws-s3/test/test.util.ts index 4a2173a9786c5..e95d3946e76ed 100644 --- a/packages/@aws-cdk/aws-s3/test/test.util.ts +++ b/packages/@aws-cdk/aws-s3/test/test.util.ts @@ -1,18 +1,17 @@ import cdk = require('@aws-cdk/cdk'); import { Test } from 'nodeunit'; -import s3 = require('../lib'); import { parseBucketArn, parseBucketName } from '../lib/util'; export = { parseBucketArn: { 'explicit arn'(test: Test) { - const bucketArn = new s3.BucketArn('my:bucket:arn'); + const bucketArn = 'my:bucket:arn'; test.deepEqual(parseBucketArn({ bucketArn }), bucketArn); test.done(); }, 'produce arn from bucket name'(test: Test) { - const bucketName = new s3.BucketName('hello'); + const bucketName = 'hello'; test.deepEqual(cdk.resolve(parseBucketArn({ bucketName })), { 'Fn::Join': [ '', [ 'arn', @@ -38,37 +37,37 @@ export = { parseBucketName: { 'explicit name'(test: Test) { - const bucketName = new s3.BucketName('foo'); + const bucketName = 'foo'; test.deepEqual(cdk.resolve(parseBucketName({ bucketName })), 'foo'); test.done(); }, 'extract bucket name from string arn'(test: Test) { - const bucketArn = new s3.BucketArn('arn:aws:s3:::my-bucket'); + const bucketArn = 'arn:aws:s3:::my-bucket'; test.deepEqual(cdk.resolve(parseBucketName({ bucketArn })), 'my-bucket'); test.done(); }, 'undefined if cannot extract name from a non-string arn'(test: Test) { - const bucketArn = new s3.BucketArn(new cdk.FnConcat('arn:aws:s3:::', 'my-bucket')); + const bucketArn = new cdk.FnConcat('arn:aws:s3:::', 'my-bucket').toString(); test.deepEqual(cdk.resolve(parseBucketName({ bucketArn })), undefined); test.done(); }, 'fails if arn uses a non "s3" service'(test: Test) { - const bucketArn = new s3.BucketArn('arn:aws:xx:::my-bucket'); + const bucketArn = 'arn:aws:xx:::my-bucket'; test.throws(() => parseBucketName({ bucketArn }), /Invalid ARN/); test.done(); }, 'fails if ARN has invalid format'(test: Test) { - const bucketArn = new s3.BucketArn('invalid-arn'); + const bucketArn = 'invalid-arn'; test.throws(() => parseBucketName({ bucketArn }), /ARNs must have at least 6 components/); test.done(); }, 'fails if ARN has path'(test: Test) { - const bucketArn = new s3.BucketArn('arn:aws:s3:::my-bucket/path'); + const bucketArn = 'arn:aws:s3:::my-bucket/path'; test.throws(() => parseBucketName({ bucketArn }), /Bucket ARN must not contain a path/); test.done(); } diff --git a/packages/@aws-cdk/aws-sqs/test/test.sqs.ts b/packages/@aws-cdk/aws-sqs/test/test.sqs.ts index 557a5be6a3abf..9d18c53027fd0 100644 --- a/packages/@aws-cdk/aws-sqs/test/test.sqs.ts +++ b/packages/@aws-cdk/aws-sqs/test/test.sqs.ts @@ -55,7 +55,7 @@ export = { 'addToPolicy will automatically create a policy for this queue'(test: Test) { const stack = new Stack(); const queue = new sqs.Queue(stack, 'MyQueue'); - queue.addToResourcePolicy(new PolicyStatement().addAllResources().addActions('sqs:*').addPrincipal(new ArnPrincipal(new Arn('arn')))); + queue.addToResourcePolicy(new PolicyStatement().addAllResources().addActions('sqs:*').addPrincipal(new ArnPrincipal('arn'))); expect(stack).toMatch({ "Resources": { "MyQueueE6CA6235": { diff --git a/packages/@aws-cdk/cdk/lib/cloudformation/arn.ts b/packages/@aws-cdk/cdk/lib/cloudformation/arn.ts index 07b6a3192ab69..86ea66c476d44 100644 --- a/packages/@aws-cdk/cdk/lib/cloudformation/arn.ts +++ b/packages/@aws-cdk/cdk/lib/cloudformation/arn.ts @@ -1,18 +1,20 @@ import { AwsAccountId, AwsPartition, AwsRegion, FnConcat, Token } from '..'; import { FnSelect, FnSplit } from '../cloudformation/fn'; +import { isToken } from '../core/tokens'; +import { CloudFormationToken } from './cloudformation-token'; /** * An Amazon Resource Name (ARN). * http://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html */ -export class Arn extends Token { +export class ArnUtils { /** * Creates an ARN from components. * If any component is the empty string, * an empty string will be inserted into the generated ARN * at the location that component corresponds to. */ - public static fromComponents(components: ArnComponents) { + public static fromComponents(components: ArnComponents): string { const partition = components.partition == null ? new AwsPartition() : components.partition; @@ -35,22 +37,51 @@ export class Arn extends Token { values.push(components.resourceName); } - return new Arn(new FnConcat(...values)); + return new FnConcat(...values).toString(); } /** * Given an ARN, parses it and returns components. * - * The ARN it will be parsed and validated. The separator (`sep`) will be - * set to '/' if the 6th component includes a '/', in which case, `resource` - * will be set to the value before the '/' and `resourceName` will be the - * rest. In case there is no '/', `resource` will be set to the 6th - * components and `resourceName` will be set to the rest of the string. + * If the ARN is a concrete string, it will be parsed and validated. The + * separator (`sep`) will be set to '/' if the 6th component includes a '/', + * in which case, `resource` will be set to the value before the '/' and + * `resourceName` will be the rest. In case there is no '/', `resource` will + * be set to the 6th components and `resourceName` will be set to the rest + * of the string. + * + * If the ARN includes tokens (or is a token), the ARN cannot be validated, + * since we don't have the actual value yet at the time of this function + * call. You will have to know the separator and the type of ARN. The + * resulting `ArnComponents` object will contain tokens for the + * subexpressions of the ARN, not string literals. In this case this + * function cannot properly parse the complete final resourceName (path) out + * of ARNs that use '/' to both separate the 'resource' from the + * 'resourceName' AND to subdivide the resourceName further. For example, in + * S3 ARNs: + * + * arn:aws:s3:::my_corporate_bucket/path/to/exampleobject.png + * + * After parsing the resourceName will not contain + * 'path/to/exampleobject.png' but simply 'path'. This is a limitation + * because there is no slicing functionality in CloudFormation templates. + * + * @param sep The separator used to separate resource from resourceName + * @param hasName Whether there is a name component in the ARN at all. For + * example, SNS Topics ARNs have the 'resource' component contain the topic + * name, and no 'resourceName' component. + * + * @returns an ArnComponents object which allows access to the various + * components of the ARN. * * @returns an ArnComponents object which allows access to the various * components of the ARN. */ - public static parse(arn: string): ArnComponents { + public static parse(arn: string, sepIfToken: string = '/', hasName: boolean = true): ArnComponents { + if (isToken(arn)) { + return this.parseToken(new CloudFormationToken(arn), sepIfToken, hasName); + } + const components = arn.split(':') as Array; if (components.length < 6) { @@ -164,21 +195,21 @@ export class Arn extends Token { const components = new FnSplit(':', arn); - const partition = new FnSelect(1, components); - const service = new FnSelect(2, components); - const region = new FnSelect(3, components); - const account = new FnSelect(4, components); + const partition = new FnSelect(1, components).toString(); + const service = new FnSelect(2, components).toString(); + const region = new FnSelect(3, components).toString(); + const account = new FnSelect(4, components).toString(); if (sep === ':') { - const resource = new FnSelect(5, components); - const resourceName = hasName ? new FnSelect(6, components) : undefined; + const resource = new FnSelect(5, components).toString(); + const resourceName = hasName ? new FnSelect(6, components).toString() : undefined; return { partition, service, region, account, resource, resourceName, sep }; } else { const lastComponents = new FnSplit(sep, new FnSelect(5, components)); - const resource = new FnSelect(0, lastComponents); - const resourceName = hasName ? new FnSelect(1, lastComponents) : undefined; + const resource = new FnSelect(0, lastComponents).toString(); + const resourceName = hasName ? new FnSelect(1, lastComponents).toString() : undefined; return { partition, service, region, account, resource, resourceName, sep }; } @@ -187,15 +218,15 @@ export class Arn extends Token { /** * Return a Token that represents the resource component of the ARN */ - public resourceComponent(sep: string = '/'): Token { - return Arn.parseToken(this, sep).resource; + public static resourceComponent(arn: string, sep: string = '/'): string { + return ArnUtils.parseToken(new Token(arn), sep).resource; } /** * Return a Token that represents the resource Name component of the ARN */ - public resourceNameComponent(sep: string = '/'): Token { - return Arn.parseToken(this, sep, true).resourceName!; + public static resourceNameComponent(arn: string, sep: string = '/'): string { + return ArnUtils.parseToken(new Token(arn), sep, true).resourceName!; } } @@ -208,13 +239,13 @@ export interface ArnComponents { * * @default The AWS partition the stack is deployed to. */ - partition?: any; + partition?: string; /** * The service namespace that identifies the AWS product (for example, * 's3', 'iam', 'codepipline'). */ - service: any; + service: string; /** * The region the resource resides in. Note that the ARNs for some resources @@ -222,7 +253,7 @@ export interface ArnComponents { * * @default The region the stack is deployed to. */ - region?: any; + region?: string; /** * The ID of the AWS account that owns the resource, without the hyphens. @@ -231,13 +262,13 @@ export interface ArnComponents { * * @default The account the stack is deployed to. */ - account?: any; + account?: string; /** * Resource type (e.g. "table", "autoScalingGroup", "certificate"). * For some resource types, e.g. S3 buckets, this field defines the bucket name. */ - resource: any; + resource: string; /** * Separator between resource type and the resource. @@ -251,5 +282,5 @@ export interface ArnComponents { * Resource name or path within the resource (i.e. S3 bucket object key) or * a wildcard such as ``"*"``. This is service-dependent. */ - resourceName?: any; + resourceName?: string; } diff --git a/packages/@aws-cdk/cdk/lib/cloudformation/permission.ts b/packages/@aws-cdk/cdk/lib/cloudformation/permission.ts index c1ce5f3f7e0cd..8cbf2de69d9b0 100644 --- a/packages/@aws-cdk/cdk/lib/cloudformation/permission.ts +++ b/packages/@aws-cdk/cdk/lib/cloudformation/permission.ts @@ -1,6 +1,4 @@ import { Token } from '../core/tokens'; -import { Arn } from './arn'; -import { FnConcat } from './fn'; import { AwsAccountId, AwsPartition } from './pseudo'; export class PolicyDocument extends Token { @@ -74,7 +72,7 @@ export class PrincipalPolicyFragment { } export class ArnPrincipal extends PolicyPrincipal { - constructor(public readonly arn: Arn) { + constructor(public readonly arn: string) { super(); } @@ -85,7 +83,7 @@ export class ArnPrincipal extends PolicyPrincipal { export class AccountPrincipal extends ArnPrincipal { constructor(public readonly accountId: any) { - super(new Arn(new FnConcat('arn:', new AwsPartition(), ':iam::', accountId, ':root'))); + super(`arn:${new AwsPartition()}:iam::${accountId}:root`); } } @@ -210,7 +208,7 @@ export class PolicyStatement extends Token { return this; } - public addAwsPrincipal(arn: Arn): PolicyStatement { + public addAwsPrincipal(arn: string): PolicyStatement { return this.addPrincipal(new ArnPrincipal(arn)); } @@ -234,8 +232,8 @@ export class PolicyStatement extends Token { // Resources // - public addResource(resource: Arn): PolicyStatement { - this.resource.push(resource); + public addResource(arn: string): PolicyStatement { + this.resource.push(arn); return this; } @@ -243,11 +241,11 @@ export class PolicyStatement extends Token { * Adds a ``"*"`` resource to this statement. */ public addAllResources(): PolicyStatement { - return this.addResource(new Arn('*')); + return this.addResource('*'); } - public addResources(...resources: Arn[]): PolicyStatement { - resources.forEach(r => this.addResource(r)); + public addResources(...arns: string[]): PolicyStatement { + arns.forEach(r => this.addResource(r)); return this; } diff --git a/packages/@aws-cdk/cdk/lib/cloudformation/resource.ts b/packages/@aws-cdk/cdk/lib/cloudformation/resource.ts index 42b17425057c2..208913893f447 100644 --- a/packages/@aws-cdk/cdk/lib/cloudformation/resource.ts +++ b/packages/@aws-cdk/cdk/lib/cloudformation/resource.ts @@ -86,6 +86,13 @@ export class Resource extends StackElement { return new CloudFormationToken({ 'Fn::GetAtt': [this.logicalId, attributeName] }, `${this.logicalId}.${attributeName}`); } + /** + * Returns a token that resolves to `{ "Ref": LogicalID }` + */ + public get ref() { + return new CloudFormationToken({ Ref: this.logicalId }); + } + /** * Adds a dependency on another resource. * @param other The other resource. diff --git a/packages/@aws-cdk/cdk/lib/core/tokens.ts b/packages/@aws-cdk/cdk/lib/core/tokens.ts index 2aa6ed95538ff..b5f144a41ce8c 100644 --- a/packages/@aws-cdk/cdk/lib/core/tokens.ts +++ b/packages/@aws-cdk/cdk/lib/core/tokens.ts @@ -102,11 +102,16 @@ export class Token { } /** - * Returns true if obj is a token (i.e. has the resolve() method) + * Returns true if obj is a token (i.e. has the resolve() method or is a string + * that includes token markers). * @param obj The object to test. */ export function isToken(obj: any): obj is Token { - return typeof(obj[RESOLVE_METHOD]) === 'function'; + if (typeof(obj) === 'string') { + return TOKEN_STRING_MAP.createTokenString(obj).test(); + } else { + return typeof(obj[RESOLVE_METHOD]) === 'function'; + } } /** @@ -252,11 +257,18 @@ class TokenStringMap { return `${BEGIN_TOKEN_MARKER}${key}${END_TOKEN_MARKER}`; } + /** + * Returns a `TokenString` for this string. + */ + public createTokenString(s: string) { + return new TokenString(s, BEGIN_TOKEN_MARKER, `[${VALID_KEY_CHARS}]+`, END_TOKEN_MARKER); + } + /** * Replace any Token markers in this string with their resolved values */ public resolveMarkers(s: string): any { - const str = new TokenString(s, BEGIN_TOKEN_MARKER, `[${VALID_KEY_CHARS}]+`, END_TOKEN_MARKER); + const str = this.createTokenString(s); const fragments = str.split(this.lookupToken.bind(this)); return fragments.join(); } @@ -304,18 +316,21 @@ export interface ITokenJoiner { * A string with markers in it that can be resolved to external values */ class TokenString { + private pattern: string; + constructor( private readonly str: string, private readonly beginMarker: string, private readonly idPattern: string, private readonly endMarker: string) { + this.pattern = `${regexQuote(this.beginMarker)}(${this.idPattern})${regexQuote(this.endMarker)}`; } /** * Split string on markers, substituting markers with Tokens */ public split(lookup: (id: string) => Token): TokenStringFragments { - const re = new RegExp(`${regexQuote(this.beginMarker)}(${this.idPattern})${regexQuote(this.endMarker)}`, 'g'); + const re = new RegExp(this.pattern, 'g'); const ret = new TokenStringFragments(); let rest = 0; @@ -337,6 +352,14 @@ class TokenString { return ret; } + + /** + * Indicates if this string includes tokens. + */ + public test(): boolean { + const re = new RegExp(this.pattern, 'g'); + return re.test(this.str); + } } /** diff --git a/packages/@aws-cdk/cdk/test/cloudformation/test.arn.ts b/packages/@aws-cdk/cdk/test/cloudformation/test.arn.ts index 965cd0dbdb7ca..2c778cf553f0f 100644 --- a/packages/@aws-cdk/cdk/test/cloudformation/test.arn.ts +++ b/packages/@aws-cdk/cdk/test/cloudformation/test.arn.ts @@ -1,9 +1,9 @@ import { Test } from 'nodeunit'; -import { Arn, ArnComponents, resolve, Token } from '../../lib'; +import { ArnComponents, ArnUtils, resolve, Token } from '../../lib'; export = { 'create from components with defaults'(test: Test) { - const arn = Arn.fromComponents({ + const arn = ArnUtils.fromComponents({ service: 'sqs', resource: 'myqueuename' }); @@ -25,7 +25,7 @@ export = { }, 'create from components with specific values for the various components'(test: Test) { - const arn = Arn.fromComponents({ + const arn = ArnUtils.fromComponents({ service: 'dynamodb', resource: 'table', account: '123456789012', @@ -53,7 +53,7 @@ export = { }, 'allow empty string in components'(test: Test) { - const arn = Arn.fromComponents({ + const arn = ArnUtils.fromComponents({ service: 's3', resource: 'my-bucket', account: '', @@ -84,7 +84,7 @@ export = { }, 'resourcePathSep can be set to ":" instead of the default "/"'(test: Test) { - const arn = Arn.fromComponents({ + const arn = ArnUtils.fromComponents({ service: 'codedeploy', resource: 'application', sep: ':', @@ -110,7 +110,7 @@ export = { }, 'fails if resourcePathSep is neither ":" nor "/"'(test: Test) { - test.throws(() => Arn.fromComponents({ + test.throws(() => ArnUtils.fromComponents({ service: 'foo', resource: 'bar', sep: 'x' })); @@ -121,22 +121,22 @@ export = { 'fails': { 'if doesn\'t start with "arn:"'(test: Test) { - test.throws(() => Arn.parse("barn:foo:x:a:1:2"), /ARNs must start with "arn:": barn:foo/); + test.throws(() => ArnUtils.parse("barn:foo:x:a:1:2"), /ARNs must start with "arn:": barn:foo/); test.done(); }, 'if the ARN doesnt have enough components'(test: Test) { - test.throws(() => Arn.parse('arn:is:too:short'), /ARNs must have at least 6 components: arn:is:too:short/); + test.throws(() => ArnUtils.parse('arn:is:too:short'), /ARNs must have at least 6 components: arn:is:too:short/); test.done(); }, 'if "service" is not specified'(test: Test) { - test.throws(() => Arn.parse('arn:aws::4:5:6'), /The `service` component \(3rd component\) is required/); + test.throws(() => ArnUtils.parse('arn:aws::4:5:6'), /The `service` component \(3rd component\) is required/); test.done(); }, 'if "resource" is not specified'(test: Test) { - test.throws(() => Arn.parse('arn:aws:service:::'), /The `resource` component \(6th component\) is required/); + test.throws(() => ArnUtils.parse('arn:aws:service:::'), /The `resource` component \(6th component\) is required/); test.done(); } }, @@ -183,7 +183,7 @@ export = { Object.keys(tests).forEach(arn => { const expected = tests[arn]; - test.deepEqual(Arn.parse(arn), expected, arn); + test.deepEqual(ArnUtils.parse(arn), expected, arn); }); test.done(); @@ -191,7 +191,7 @@ export = { 'a Token with : separator'(test: Test) { const theToken = { Ref: 'SomeParameter' }; - const parsed = Arn.parseToken(new Token(() => theToken), ':'); + const parsed = ArnUtils.parseToken(new Token(() => theToken), ':'); test.deepEqual(resolve(parsed.partition), { 'Fn::Select': [ 1, { 'Fn::Split': [ ':', theToken ]} ]}); test.deepEqual(resolve(parsed.service), { 'Fn::Select': [ 2, { 'Fn::Split': [ ':', theToken ]} ]}); @@ -206,7 +206,7 @@ export = { 'a Token with / separator'(test: Test) { const theToken = { Ref: 'SomeParameter' }; - const parsed = Arn.parseToken(new Token(() => theToken)); + const parsed = ArnUtils.parseToken(new Token(() => theToken)); test.equal(parsed.sep, '/'); diff --git a/packages/@aws-cdk/cdk/test/cloudformation/test.perms.ts b/packages/@aws-cdk/cdk/test/cloudformation/test.perms.ts index 6207ef63aceda..062313316ef37 100644 --- a/packages/@aws-cdk/cdk/test/cloudformation/test.perms.ts +++ b/packages/@aws-cdk/cdk/test/cloudformation/test.perms.ts @@ -1,13 +1,13 @@ import { Test } from 'nodeunit'; -import { Arn, CanonicalUserPrincipal, FnConcat, PolicyDocument, PolicyStatement, resolve } from '../../lib'; +import { CanonicalUserPrincipal, FnConcat, PolicyDocument, PolicyStatement, resolve } from '../../lib'; export = { 'the Permission class is a programming model for iam'(test: Test) { const p = new PolicyStatement(); p.addAction('sqs:SendMessage'); p.addActions('dynamodb:CreateTable', 'dynamodb:DeleteTable'); - p.addResource(new Arn('myQueue')); - p.addResource(new Arn('yourQueue')); + p.addResource('myQueue'); + p.addResource('yourQueue'); p.addAllResources(); p.addAwsAccountPrincipal(new FnConcat('my', 'account', 'name').toString()); @@ -37,7 +37,7 @@ export = { const doc = new PolicyDocument(); const p1 = new PolicyStatement(); p1.addAction('sqs:SendMessage'); - p1.addResource(new Arn('*')); + p1.addResource('*'); const p2 = new PolicyStatement(); p2.deny(); @@ -65,7 +65,7 @@ export = { ] }; const doc = new PolicyDocument(base); - doc.addStatement(new PolicyStatement().addResource(new Arn('resource')).addAction('action')); + doc.addStatement(new PolicyStatement().addResource('resource').addAction('action')); test.deepEqual(resolve(doc), { Version: 'Foo', Something: 123, @@ -77,7 +77,7 @@ export = { }, 'Permission allows specifying multiple actions upon construction'(test: Test) { - const perm = new PolicyStatement().addResource(new Arn('MyResource')).addActions('Action1', 'Action2', 'Action3'); + const perm = new PolicyStatement().addResource('MyResource').addActions('Action1', 'Action2', 'Action3'); test.deepEqual(resolve(perm), { Effect: 'Allow', Action: [ 'Action1', 'Action2', 'Action3' ], @@ -150,7 +150,7 @@ export = { 'true if there is one resource'(test: Test) { test.equal( - new PolicyStatement().addResource(new Arn('one-resource')).hasResource, + new PolicyStatement().addResource('one-resource').hasResource, true, 'hasResource is true when there is one resource'); test.done(); @@ -158,8 +158,8 @@ export = { 'true for multiple resources'(test: Test) { const p = new PolicyStatement(); - p.addResource(new Arn('r1')); - p.addResource(new Arn('r2')); + p.addResource('r1'); + p.addResource('r2'); test.equal(p.hasResource, true, 'hasResource is true when there are multiple resource'); test.done(); }, @@ -173,7 +173,7 @@ export = { 'true if there is a principal'(test: Test) { const p = new PolicyStatement(); - p.addAwsPrincipal(new Arn('bla')); + p.addAwsPrincipal('bla'); test.equal(p.hasPrincipal, true); test.done(); } diff --git a/packages/@aws-cdk/cdk/test/cloudformation/test.resource.ts b/packages/@aws-cdk/cdk/test/cloudformation/test.resource.ts index 4941bf0ad8448..ea41cb5e43a66 100644 --- a/packages/@aws-cdk/cdk/test/cloudformation/test.resource.ts +++ b/packages/@aws-cdk/cdk/test/cloudformation/test.resource.ts @@ -1,7 +1,7 @@ import { Test } from 'nodeunit'; -import { applyRemovalPolicy, Arn, Condition, Construct, DeletionPolicy, +import { applyRemovalPolicy, Condition, Construct, DeletionPolicy, FnEquals, FnNot, HashedAddressingScheme, IDependable, PolicyStatement, - RemovalPolicy, Resource, Root, Stack, Token } from '../../lib'; + RemovalPolicy, resolve, Resource, Root, Stack } from '../../lib'; export = { 'all resources derive from Resource, which derives from Entity'(test: Test) { @@ -340,6 +340,14 @@ export = { 'MyC3C2R38CE6F9F7' ] } } }); test.done(); }, + + 'resource.ref returns the {Ref} token'(test: Test) { + const stack = new Stack(); + const r = new Resource(stack, 'MyResource', { type: 'R' }); + + test.deepEqual(resolve(r), {}); + test.done(); + } }; interface CounterProps { @@ -348,13 +356,13 @@ interface CounterProps { } class Counter extends Resource { - public readonly arn: CounterArnAttr; - public readonly url: CounterUrlAttr; + public readonly arn: string; + public readonly url: string; constructor(parent: Construct, name: string, props: CounterProps) { super(parent, name, { type: 'My::Counter', properties: { Count: props.Count } }); - this.arn = new CounterArnAttr(this.getAtt('Arn')); - this.url = new CounterUrlAttr(() => this.getAtt('URL')); + this.arn = this.getAtt('Arn').toString(); + this.url = this.getAtt('URL').toString(); } public increment(by = 1) { @@ -362,9 +370,6 @@ class Counter extends Resource { } } -class CounterArnAttr extends Arn { } -class CounterUrlAttr extends Token { } - function withoutHash(logId: string) { return logId.substr(0, logId.length - 8); } diff --git a/tools/cfn2ts/lib/codegen.ts b/tools/cfn2ts/lib/codegen.ts index b3ee81f601c5a..81cf89029b976 100644 --- a/tools/cfn2ts/lib/codegen.ts +++ b/tools/cfn2ts/lib/codegen.ts @@ -79,9 +79,7 @@ export default class CodeGenerator { this.code.closeBlock(); - if (attributeTypes.length === 0) { continue; } for (const attributeType of attributeTypes) { - this.code.line(); this.emitAttributeType(attributeType); } } @@ -227,11 +225,12 @@ export default class CodeGenerator { if (spec.Attributes) { for (const attributeName of Object.keys(spec.Attributes).sort()) { + const attributeSpec = spec.Attributes![attributeName]; + this.code.line(); this.docLink(undefined, `@cloudformation_attribute ${attributeName}`); - - const attr = genspec.attributeDefinition(resourceName, attributeName, undefined); + const attr = genspec.attributeDefinition(resourceName, attributeName, attributeSpec); this.code.line(`public readonly ${attr.propertyName}: ${attr.attributeType.typeName.className};`); @@ -245,13 +244,11 @@ export default class CodeGenerator { // if (spec.RefKind !== schema.SpecialRefKind.None) { const refAttribute = genspec.refAttributeDefinition(resourceName, spec.RefKind!); - this.code.line(`public readonly ${refAttribute.propertyName}: ${refAttribute.attributeType.typeName.className};`); - // If there's already an attribute with the same declared type, we don't have to duplicate - // the type, but we do have to initialize the attribute variable. - attributes.push(refAttribute); - const alreadyAnAttributeType = attributeTypes.some(t => t.typeName.fqn === refAttribute.attributeType.typeName.fqn); - if (!alreadyAnAttributeType) { + // If there's already an attribute with the same name, ref is not needed + if (!attributes.some(a => a.propertyName === refAttribute.propertyName)) { + this.code.line(`public readonly ${refAttribute.propertyName}: ${refAttribute.attributeType.typeName.className};`); + attributes.push(refAttribute); attributeTypes.push(refAttribute.attributeType); } } @@ -294,7 +291,15 @@ export default class CodeGenerator { // initialize all attribute properties for (const at of attributes) { - this.code.line(`this.${at.propertyName} = new ${at.attributeType.typeName.className}(${at.constructorArguments});`); + if (at.attributeType.isPrimitive) { + if (at.attributeType.typeName.className === 'string') { + this.code.line(`this.${at.propertyName} = ${at.constructorArguments}.toString();`); + } else { + throw new Error(`Unsupported primitive attribute type ${at.attributeType.typeName.className}`); + } + } else { + this.code.line(`this.${at.propertyName} = new ${at.attributeType.typeName.className}(${at.constructorArguments});`); + } } this.code.closeBlock(); @@ -476,6 +481,11 @@ export default class CodeGenerator { * Attribute types are classes that represent resource attributes (e.g. QueueArnAttribute). */ private emitAttributeType(attr: genspec.ClassDeclaration) { + if (!attr.baseClassName) { + return; // primitive, no attribute type generated + } + + this.code.line(); this.openClass(attr.typeName, attr.docLink, attr.baseClassName.fqn); // Add a private member that will make the class structurally // different in TypeScript, which prevents assigning returning diff --git a/tools/cfn2ts/lib/genspec.ts b/tools/cfn2ts/lib/genspec.ts index b43ebefb07e2d..7d34a564b2233 100644 --- a/tools/cfn2ts/lib/genspec.ts +++ b/tools/cfn2ts/lib/genspec.ts @@ -107,10 +107,14 @@ export class CodeName { export class ClassDeclaration { constructor( readonly typeName: CodeName, - readonly baseClassName: CodeName, + readonly baseClassName?: CodeName, readonly docLink?: string ) { } + + public get isPrimitive() { + return !this.baseClassName; + } } export const TAG_NAME = new CodeName('', CORE_NAMESPACE, 'Tag'); @@ -184,17 +188,22 @@ export function validatorName(typeName: CodeName): CodeName { * - The type we will generate for the attribute, including its base class and docs. * - The property name we will use to refer to the attribute. */ -export function attributeDefinition(resourceName: CodeName, attributeName: string, docLink?: string): Attribute { +export function attributeDefinition(resourceName: CodeName, attributeName: string, spec: schema.Attribute): Attribute { const descriptiveName = descriptiveAttributeName(resourceName, attributeName); // "BucketArn" const propertyName = cloudFormationToScriptName(descriptiveName); // "bucketArn" - // Not in a namespace, base the name on the descriptive name - const typeName = new CodeName(resourceName.packageName, '', descriptiveName); // "BucketArn" - const baseClass = attributeName.endsWith('Arn') ? ARN_NAME : TOKEN_NAME; + let attrType; + if ('PrimitiveType' in spec && spec.PrimitiveType === 'String') { + attrType = new ClassDeclaration(CodeName.forPrimitive('string')); + } else { + // Not in a namespace, base the name on the descriptive name + const typeName = new CodeName(resourceName.packageName, '', descriptiveName); // "BucketArn" + const baseClass = attributeName.endsWith('Arn') ? ARN_NAME : TOKEN_NAME; + + attrType = new ClassDeclaration(typeName, baseClass, undefined); + } const constructorArguments = `this.getAtt('${attributeName}')`; - - const attrType = new ClassDeclaration(typeName, baseClass, docLink); return new Attribute(propertyName, attrType, constructorArguments); } @@ -202,14 +211,12 @@ export function attributeDefinition(resourceName: CodeName, attributeName: strin * Return an attribute definition name for the RefKind for this class */ export function refAttributeDefinition(resourceName: CodeName, refKind: string): Attribute { - const refClassName = descriptiveAttributeName(resourceName, refKind); - const refClass = new CodeName(resourceName.packageName, '', refClassName); - const baseClass = refKind === schema.SpecialRefKind.Arn ? ARN_NAME : TOKEN_NAME; + const propertyName = codemaker.toCamelCase(descriptiveAttributeName(resourceName, refKind)); - const constructorArguments = '{ Ref: this.logicalId }, `${this.logicalId}.Ref`'; + const constructorArguments = 'this.ref'; - const refType = new ClassDeclaration(refClass, baseClass); - return new Attribute('ref', refType, constructorArguments); + const refType = new ClassDeclaration(CodeName.forPrimitive('string')); + return new Attribute(propertyName, refType, constructorArguments); } /** From 32da3528f205cd98c88468f6f5718553349996df Mon Sep 17 00:00:00 2001 From: Elad Ben-Israel Date: Mon, 17 Sep 2018 21:30:53 +0300 Subject: [PATCH 02/13] Updates * Converted all attribute types to strings * Remove a stale example from aws-cloudformation * Add `--no-bail` to `build.sh` so it won't stop on the first error * Reduce some verbosity from cdk-build and cfn2ts --- build.sh | 2 +- docs/src/examples.rst | 4 +- .../cdk-examples-typescript/chat-app/index.ts | 2 +- .../neptune-demo/index.ts | 5 +- packages/@aws-cdk/assets/lib/asset.ts | 16 +-- .../aws-autoscaling/lib/auto-scaling-group.ts | 2 +- .../test/test.auto-scaling-group.ts | 8 +- .../lib/certificate-ref.ts | 9 +- .../aws-certificatemanager/lib/certificate.ts | 6 +- .../aws-cloudformation/examples/cdk.json | 3 - .../aws-cloudformation/examples/index.ts | 104 ------------------ .../aws-cloudformation/examples/provider.py | 26 ----- .../test/integ.trivial-lambda-resource.ts | 4 +- .../aws-cloudfront/lib/web_distribution.ts | 7 +- packages/@aws-cdk/aws-cloudtrail/lib/index.ts | 10 +- packages/@aws-cdk/aws-cloudwatch/lib/alarm.ts | 38 +++---- packages/@aws-cdk/aws-cloudwatch/lib/graph.ts | 10 +- .../aws-cloudwatch/test/test.alarm.ts | 2 +- .../@aws-cdk/aws-codebuild/lib/project.ts | 31 +++--- .../@aws-cdk/aws-codecommit/lib/repository.ts | 18 +-- .../aws-codedeploy/lib/application.ts | 24 ++-- .../aws-codedeploy/lib/deployment-group.ts | 29 ++--- .../aws-codedeploy/lib/pipeline-action.ts | 6 +- .../aws-codepipeline-api/lib/action.ts | 2 +- .../aws-codepipeline-api/lib/artifact.ts | 36 +++--- .../@aws-cdk/aws-codepipeline/lib/pipeline.ts | 19 ++-- .../@aws-cdk/aws-codepipeline/lib/stage.ts | 2 +- packages/@aws-cdk/aws-dynamodb/lib/table.ts | 10 +- .../aws-ec2/lib/security-group-rule.ts | 3 +- .../@aws-cdk/aws-ec2/lib/security-group.ts | 18 +-- packages/@aws-cdk/aws-ec2/lib/util.ts | 11 +- packages/@aws-cdk/aws-ec2/lib/vpc-ref.ts | 21 ++-- packages/@aws-cdk/aws-ec2/lib/vpc.ts | 28 ++--- .../@aws-cdk/aws-ec2/test/test.connections.ts | 4 +- packages/@aws-cdk/aws-ec2/test/test.vpc.ts | 4 +- .../@aws-cdk/aws-ecr/lib/repository-ref.ts | 10 +- .../lib/load-balancer.ts | 2 +- .../@aws-cdk/aws-events/lib/event-pattern.ts | 4 +- packages/@aws-cdk/aws-events/lib/target.ts | 6 +- .../@aws-cdk/aws-events/test/test.rule.ts | 19 ++-- packages/@aws-cdk/aws-kinesis/lib/stream.ts | 28 ++--- packages/@aws-cdk/aws-kms/test/integ.key.ts | 2 +- packages/@aws-cdk/aws-kms/test/test.key.ts | 2 +- packages/@aws-cdk/aws-lambda/lib/alias.ts | 10 +- packages/@aws-cdk/aws-lambda/lib/code.ts | 2 +- .../@aws-cdk/aws-lambda/lib/lambda-ref.ts | 33 +++--- .../@aws-cdk/aws-lambda/lib/lambda-version.ts | 4 +- packages/@aws-cdk/aws-lambda/lib/lambda.ts | 8 +- .../@aws-cdk/aws-lambda/lib/permission.ts | 4 +- .../aws-lambda/lib/singleton-lambda.ts | 5 +- .../@aws-cdk/aws-lambda/test/test.lambda.ts | 4 +- .../aws-logs/lib/cross-account-destination.ts | 10 +- packages/@aws-cdk/aws-logs/lib/log-group.ts | 22 ++-- packages/@aws-cdk/aws-logs/lib/log-stream.ts | 14 +-- .../aws-logs/lib/subscription-filter.ts | 2 +- .../aws-logs/test/test.destination.ts | 4 +- .../aws-logs/test/test.subscriptionfilter.ts | 2 +- packages/@aws-cdk/aws-neptune/lib/index.ts | 7 +- .../@aws-cdk/aws-neptune/test/test.neptune.ts | 5 +- packages/@aws-cdk/aws-quickstarts/lib/rdgw.ts | 2 +- packages/@aws-cdk/aws-rds/lib/cluster-ref.ts | 56 +++++----- packages/@aws-cdk/aws-rds/lib/cluster.ts | 17 ++- packages/@aws-cdk/aws-rds/lib/props.ts | 15 +-- .../@aws-cdk/aws-rds/test/integ.cluster.ts | 6 +- .../@aws-cdk/aws-rds/test/test.cluster.ts | 14 +-- .../aws-route53/lib/hosted-zone-ref.ts | 9 +- .../@aws-cdk/aws-route53/lib/hosted-zone.ts | 9 +- packages/@aws-cdk/aws-s3/lib/bucket.ts | 18 +-- .../notifications-resource-handler.ts | 6 +- packages/@aws-cdk/aws-s3/lib/util.ts | 2 +- .../aws-s3/test/test.notifications.ts | 14 +-- packages/@aws-cdk/aws-sns/lib/topic-ref.ts | 23 ++-- packages/@aws-cdk/aws-sns/lib/topic.ts | 6 +- packages/@aws-cdk/aws-sns/test/test.sns.ts | 6 +- packages/@aws-cdk/aws-sqs/lib/queue-ref.ts | 23 ++-- packages/@aws-cdk/aws-sqs/lib/queue.ts | 12 +- packages/@aws-cdk/aws-sqs/test/test.sqs.ts | 2 +- .../@aws-cdk/cdk/lib/cloudformation/output.ts | 2 +- .../cdk/lib/cloudformation/parameter.ts | 4 +- .../cdk/lib/cloudformation/resource.ts | 16 +-- .../@aws-cdk/cdk/lib/cloudformation/secret.ts | 8 +- .../@aws-cdk/cdk/lib/cloudformation/stack.ts | 4 +- .../@aws-cdk/cdk/lib/cloudformation/tag.ts | 6 +- .../cdk/test/cloudformation/test.resource.ts | 2 +- packages/@aws-cdk/runtime-values/lib/rtv.ts | 17 +-- tools/cdk-build-tools/bin/cdk-build.ts | 1 - tools/cfn2ts/lib/index.ts | 2 - 87 files changed, 395 insertions(+), 640 deletions(-) delete mode 100644 packages/@aws-cdk/aws-cloudformation/examples/cdk.json delete mode 100644 packages/@aws-cdk/aws-cloudformation/examples/index.ts delete mode 100644 packages/@aws-cdk/aws-cloudformation/examples/provider.py diff --git a/build.sh b/build.sh index 7eda08d2cc984..af24eac27e587 100755 --- a/build.sh +++ b/build.sh @@ -19,7 +19,7 @@ trap "rm -rf $MERKLE_BUILD_CACHE" EXIT echo "=============================================================================================" echo "building..." -time lerna exec --stream "npm run build" +time lerna exec --no-bail --stream "npm run build" echo "=============================================================================================" echo "testing..." diff --git a/docs/src/examples.rst b/docs/src/examples.rst index 018cd72f12047..f3d3bad4350f3 100644 --- a/docs/src/examples.rst +++ b/docs/src/examples.rst @@ -168,8 +168,8 @@ The following example creates the Aurora database **MyAuroraDatabase**. new rds.DatabaseCluster(this, 'MyRdsDb', { defaultDatabaseName: 'MyAuroraDatabase', masterUser: { - username: new cdk.Token('admin'), - password: new cdk.Token('123456') + username: 'admin', + password: '123456' }, engine: rds.DatabaseClusterEngine.Aurora, instanceProps: { diff --git a/examples/cdk-examples-typescript/chat-app/index.ts b/examples/cdk-examples-typescript/chat-app/index.ts index 4bf4e6b768413..a87fae99d73ba 100644 --- a/examples/cdk-examples-typescript/chat-app/index.ts +++ b/examples/cdk-examples-typescript/chat-app/index.ts @@ -13,7 +13,7 @@ class MyStack extends cdk.Stack { new CognitoChatRoomPool(this, 'UserPool'); const bucket = s3.BucketRef.import(this, 'DougsBucket', { - bucketName: new s3.BucketName('dougs-chat-app') + bucketName: 'dougs-chat-app' }); new ChatAppFunction(this, 'StartAddBucket', { diff --git a/examples/cdk-examples-typescript/neptune-demo/index.ts b/examples/cdk-examples-typescript/neptune-demo/index.ts index b6bd3136ea517..c9a247b246bb2 100644 --- a/examples/cdk-examples-typescript/neptune-demo/index.ts +++ b/examples/cdk-examples-typescript/neptune-demo/index.ts @@ -1,6 +1,5 @@ import ec2 = require('@aws-cdk/aws-ec2'); import neptune = require('@aws-cdk/aws-neptune'); -import rds = require('@aws-cdk/aws-rds'); import cdk = require('@aws-cdk/cdk'); class NeptuneDemoStack extends cdk.Stack { @@ -19,8 +18,8 @@ class NeptuneDemoStack extends cdk.Stack { masterUser: { // This would normally be imported from SSM parmeter store encrypted string, // but don't want to overcomplicate the example - username: new rds.Username('admin'), - password: new rds.Password('eRSDwst7lpzu'), + username: 'admin', + password: 'eRSDwst7lpzu', } }); database.connections.allowDefaultPortFrom(new ec2.AnyIPv4(), 'Allow the world to connect'); diff --git a/packages/@aws-cdk/assets/lib/asset.ts b/packages/@aws-cdk/assets/lib/asset.ts index 35fc91fbfe643..d7105c4d1c897 100644 --- a/packages/@aws-cdk/assets/lib/asset.ts +++ b/packages/@aws-cdk/assets/lib/asset.ts @@ -47,18 +47,18 @@ export class Asset extends cdk.Construct { /** * Attribute that represents the name of the bucket this asset exists in. */ - public readonly s3BucketName: s3.BucketName; + public readonly s3BucketName: string; /** * Attribute which represents the S3 object key of this asset. */ - public readonly s3ObjectKey: s3.ObjectKey; + public readonly s3ObjectKey: string; /** * Attribute which represents the S3 URL of this asset. * @example https://s3.us-west-1.amazonaws.com/bucket/key */ - public readonly s3Url: s3.S3Url; + public readonly s3Url: string; /** * Resolved full-path location of this asset. @@ -70,7 +70,7 @@ export class Asset extends cdk.Construct { /** * The S3 prefix where all different versions of this asset are stored */ - private readonly s3Prefix: cdk.Token; + private readonly s3Prefix: string; constructor(parent: cdk.Construct, id: string, props: GenericAssetProps) { super(parent, id); @@ -94,10 +94,10 @@ export class Asset extends cdk.Construct { description: `S3 key for asset version "${this.path}"` }); - this.s3BucketName = new s3.BucketName(bucketParam.value); - this.s3Prefix = new cdk.FnSelect(0, new cdk.FnSplit(cxapi.ASSET_PREFIX_SEPARATOR, keyParam.value)); - const s3Filename = new cdk.FnSelect(1, new cdk.FnSplit(cxapi.ASSET_PREFIX_SEPARATOR, keyParam.value)); - this.s3ObjectKey = new s3.ObjectKey(new cdk.FnConcat(this.s3Prefix, s3Filename)); + this.s3BucketName = bucketParam.value.toString(); + this.s3Prefix = new cdk.FnSelect(0, new cdk.FnSplit(cxapi.ASSET_PREFIX_SEPARATOR, keyParam.value)).toString(); + const s3Filename = new cdk.FnSelect(1, new cdk.FnSplit(cxapi.ASSET_PREFIX_SEPARATOR, keyParam.value)).toString(); + this.s3ObjectKey = `${this.s3Prefix}${s3Filename}`; this.bucket = s3.BucketRef.import(parent, 'AssetBucket', { bucketName: this.s3BucketName diff --git a/packages/@aws-cdk/aws-autoscaling/lib/auto-scaling-group.ts b/packages/@aws-cdk/aws-autoscaling/lib/auto-scaling-group.ts index 26bb60f910fef..4dfb06267c5a7 100644 --- a/packages/@aws-cdk/aws-autoscaling/lib/auto-scaling-group.ts +++ b/packages/@aws-cdk/aws-autoscaling/lib/auto-scaling-group.ts @@ -156,7 +156,7 @@ export class AutoScalingGroup extends cdk.Construct implements elb.ILoadBalancer private readonly autoScalingGroup: cloudformation.AutoScalingGroupResource; private readonly securityGroup: ec2.SecurityGroupRef; private readonly securityGroups: ec2.SecurityGroupRef[] = []; - private readonly loadBalancerNames: cdk.Token[] = []; + private readonly loadBalancerNames: string[] = []; constructor(parent: cdk.Construct, name: string, props: AutoScalingGroupProps) { super(parent, name); diff --git a/packages/@aws-cdk/aws-autoscaling/test/test.auto-scaling-group.ts b/packages/@aws-cdk/aws-autoscaling/test/test.auto-scaling-group.ts index d2d88bf47d87c..1f5964128aedb 100644 --- a/packages/@aws-cdk/aws-autoscaling/test/test.auto-scaling-group.ts +++ b/packages/@aws-cdk/aws-autoscaling/test/test.auto-scaling-group.ts @@ -360,16 +360,16 @@ export = { function mockVpc(stack: cdk.Stack) { return ec2.VpcNetwork.import(stack, 'MyVpc', { - vpcId: new ec2.VPCId('my-vpc'), + vpcId: 'my-vpc', availabilityZones: [ 'az1' ], - publicSubnetIds: [ new ec2.SubnetId('pub1') ], - privateSubnetIds: [ new ec2.SubnetId('pri1') ], + publicSubnetIds: [ 'pub1' ], + privateSubnetIds: [ 'pri1' ], isolatedSubnetIds: [], }); } function mockSecurityGroup(stack: cdk.Stack) { return ec2.SecurityGroupRef.import(stack, 'MySG', { - securityGroupId: new ec2.SecurityGroupId('most-secure'), + securityGroupId: 'most-secure', }); } diff --git a/packages/@aws-cdk/aws-certificatemanager/lib/certificate-ref.ts b/packages/@aws-cdk/aws-certificatemanager/lib/certificate-ref.ts index 4d5e9b1974ea0..5f52ee207b15f 100644 --- a/packages/@aws-cdk/aws-certificatemanager/lib/certificate-ref.ts +++ b/packages/@aws-cdk/aws-certificatemanager/lib/certificate-ref.ts @@ -1,5 +1,4 @@ import { Construct, Output } from "@aws-cdk/cdk"; -import { CertificateArn } from './certificatemanager.generated'; /** * Interface for certificate-like objects @@ -12,14 +11,14 @@ export abstract class CertificateRef extends Construct { return new ImportedCertificate(parent, name, props); } - public abstract readonly certificateArn: CertificateArn; + public abstract readonly certificateArn: string; /** * Export this certificate from the stack */ public export(): CertificateRefProps { return { - certificateArn: new CertificateArn(new Output(this, 'Arn', { value: this.certificateArn }).makeImportValue()) + certificateArn: new Output(this, 'Arn', { value: this.certificateArn }).makeImportValue().toString() }; } } @@ -28,7 +27,7 @@ export abstract class CertificateRef extends Construct { * A Certificate that has been imported from another stack */ class ImportedCertificate extends CertificateRef { - public readonly certificateArn: CertificateArn; + public readonly certificateArn: string; constructor(parent: Construct, name: string, props: CertificateRefProps) { super(parent, name); @@ -44,5 +43,5 @@ export interface CertificateRefProps { /** * The certificate's ARN */ - certificateArn: CertificateArn; + certificateArn: string; } diff --git a/packages/@aws-cdk/aws-certificatemanager/lib/certificate.ts b/packages/@aws-cdk/aws-certificatemanager/lib/certificate.ts index 99d75a7cc07f2..3d839a0416c37 100644 --- a/packages/@aws-cdk/aws-certificatemanager/lib/certificate.ts +++ b/packages/@aws-cdk/aws-certificatemanager/lib/certificate.ts @@ -1,6 +1,6 @@ import { Construct } from '@aws-cdk/cdk'; import { CertificateRef } from './certificate-ref'; -import { CertificateArn, cloudformation } from './certificatemanager.generated'; +import { cloudformation } from './certificatemanager.generated'; import { apexDomain } from './util'; /** @@ -52,7 +52,7 @@ export class Certificate extends CertificateRef { /** * The certificate's ARN */ - public readonly certificateArn: CertificateArn; + public readonly certificateArn: string; constructor(parent: Construct, name: string, props: CertificateProps) { super(parent, name); @@ -65,7 +65,7 @@ export class Certificate extends CertificateRef { domainValidationOptions: allDomainNames.map(domainValidationOption), }); - this.certificateArn = cert.ref; + this.certificateArn = cert.certificateArn; /** * Return the domain validation options for the given domain diff --git a/packages/@aws-cdk/aws-cloudformation/examples/cdk.json b/packages/@aws-cdk/aws-cloudformation/examples/cdk.json deleted file mode 100644 index b346d2f837ccb..0000000000000 --- a/packages/@aws-cdk/aws-cloudformation/examples/cdk.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "app": "node index" -} diff --git a/packages/@aws-cdk/aws-cloudformation/examples/index.ts b/packages/@aws-cdk/aws-cloudformation/examples/index.ts deleted file mode 100644 index f9b3dc452e579..0000000000000 --- a/packages/@aws-cdk/aws-cloudformation/examples/index.ts +++ /dev/null @@ -1,104 +0,0 @@ -import lambda = require('@aws-cdk/aws-lambda'); -import { cloudformation as s3 } from '@aws-cdk/aws-s3'; -import cdk = require('@aws-cdk/cdk'); -import fs = require('fs'); -import { CustomResource, SingletonLambda } from '../lib'; - -interface DemoResourceProps { - /** - * Message to echo - */ - message: string; - - /** - * Set this to true to fail the CREATE invocation - */ - failCreate?: boolean; -} - -class DemoResource extends cdk.Construct implements cdk.IDependable { - public readonly dependencyElements: cdk.IDependable[]; - public readonly response: cdk.Token; - - constructor(parent: cdk.Construct, name: string, props: DemoResourceProps) { - super(parent, name); - - const resource = new CustomResource(this, 'Resource', { - lambdaProvider: new SingletonLambda(this, 'Singleton', { - uuid: 'f7d4f730-4ee1-11e8-9c2d-fa7ae01bbebc', - // This makes the demo only work as top-level TypeScript program, but that's fine for now - code: new lambda.LambdaInlineCode(fs.readFileSync('integ.trivial-lambda-provider.py', { encoding: 'utf-8' })), - handler: 'index.main', - timeout: 300, - runtime: lambda.LambdaRuntime.Python27, - }), - properties: props - }); - - this.response = resource.getAtt('Response'); - this.dependencyElements = [resource]; - } -} - -/** - * A stack that only sets up the CustomResource and shows how to get an attribute from it - */ -class SucceedingStack extends cdk.Stack { - constructor(parent: cdk.App, name: string, props?: cdk.StackProps) { - super(parent, name, props); - - const resource = new DemoResource(this, 'DemoResource', { - message: 'CustomResource says hello', - }); - - // Publish the custom resource output - new cdk.Output(this, 'ResponseMessage', { - description: 'The message that came back from the Custom Resource', - value: resource.response - }); - } -} - -/** - * A stack that sets up a failing CustomResource creation - */ -class FailCreationStack extends cdk.Stack { - constructor(parent: cdk.App, name: string, props?: cdk.StackProps) { - super(parent, name, props); - - new DemoResource(this, 'DemoResource', { - message: 'CustomResource is silent', - failCreate: true - }); - } -} - -/** - * A stack that sets up the CustomResource and fails afterwards, to check that cleanup gets - * done properly. - */ -class FailAfterCreatingStack extends cdk.Stack { - constructor(parent: cdk.App, name: string, props?: cdk.StackProps) { - super(parent, name, props); - - const resource = new DemoResource(this, 'DemoResource', { - message: 'CustomResource says hello', - }); - - // Bucket with an invalid name will fail the deployment and cause a rollback - const bucket = new s3.BucketResource(this, 'FailingBucket', { - bucketName: 'hello!@#$^' - }); - - // Make sure the rollback gets triggered only after the custom resource has been fully created. - bucket.addDependency(resource); - } -} - -const app = new cdk.App(process.argv); - -new SucceedingStack(app, 'SucceedingStack'); -new FailCreationStack(app, 'FailCreationStack'); -new FailAfterCreatingStack(app, 'FailAfterCreatingStack'); - -process.stdout.write(app.run()); diff --git a/packages/@aws-cdk/aws-cloudformation/examples/provider.py b/packages/@aws-cdk/aws-cloudformation/examples/provider.py deleted file mode 100644 index f51514d0d3585..0000000000000 --- a/packages/@aws-cdk/aws-cloudformation/examples/provider.py +++ /dev/null @@ -1,26 +0,0 @@ -def main(event, context): - import logging as log - import cfnresponse - log.getLogger().setLevel(log.INFO) - - # This needs to change if there are to be multiple resources in the same stack - physical_id = 'TheOnlyCustomResource' - - try: - log.info('Input event: %s', event) - - # Check if this is a Create and we're failing Creates - if event['RequestType'] == 'Create' and event['ResourceProperties'].get('FailCreate', False): - raise RuntimeError('Create failure requested') - - # Do the thing - message = event['ResourceProperties']['Message'] - attributes = { - 'Response': 'You said "%s"' % message - } - - cfnresponse.send(event, context, cfnresponse.SUCCESS, attributes, physical_id) - except Exception as e: - log.exception(e) - # cfnresponse's error message is always "see CloudWatch" - cfnresponse.send(event, context, cfnresponse.FAILED, {}, physical_id) diff --git a/packages/@aws-cdk/aws-cloudformation/test/integ.trivial-lambda-resource.ts b/packages/@aws-cdk/aws-cloudformation/test/integ.trivial-lambda-resource.ts index 0eab2e20186c2..363388739c87b 100644 --- a/packages/@aws-cdk/aws-cloudformation/test/integ.trivial-lambda-resource.ts +++ b/packages/@aws-cdk/aws-cloudformation/test/integ.trivial-lambda-resource.ts @@ -16,7 +16,7 @@ interface DemoResourceProps { } class DemoResource extends cdk.Construct { - public readonly response: cdk.Token; + public readonly response: string; constructor(parent: cdk.Construct, name: string, props: DemoResourceProps) { super(parent, name); @@ -33,7 +33,7 @@ class DemoResource extends cdk.Construct { properties: props }); - this.response = resource.getAtt('Response'); + this.response = resource.getAtt('Response').toString(); } } diff --git a/packages/@aws-cdk/aws-cloudfront/lib/web_distribution.ts b/packages/@aws-cdk/aws-cloudfront/lib/web_distribution.ts index 8fbb36c82a161..a34db7292b0cf 100644 --- a/packages/@aws-cdk/aws-cloudfront/lib/web_distribution.ts +++ b/packages/@aws-cdk/aws-cloudfront/lib/web_distribution.ts @@ -1,7 +1,6 @@ -import certificatemanager = require('@aws-cdk/aws-certificatemanager'); import s3 = require('@aws-cdk/aws-s3'); import cdk = require('@aws-cdk/cdk'); -import { cloudformation, DistributionDomainName } from './cloudfront.generated'; +import { cloudformation } from './cloudfront.generated'; export enum HttpVersion { HTTP1_1 = "http1.1", @@ -40,7 +39,7 @@ export enum ViewerProtocolPolicy { */ export interface AliasConfiguration { readonly names: string[], - readonly acmCertRef: certificatemanager.CertificateArn, + readonly acmCertRef: string, readonly sslMethod?: SSLMethod, } @@ -443,7 +442,7 @@ export class CloudFrontWebDistribution extends cdk.Construct { * If you are using aliases for your distribution, this is the domainName your DNS records should point to. * (In Route53, you could create an ALIAS record to this value, for example. ) */ - public readonly domainName: DistributionDomainName; + public readonly domainName: string; /** * Maps our methods to the string arrays they are diff --git a/packages/@aws-cdk/aws-cloudtrail/lib/index.ts b/packages/@aws-cdk/aws-cloudtrail/lib/index.ts index dd5360c3c5741..0c5828bee5389 100644 --- a/packages/@aws-cdk/aws-cloudtrail/lib/index.ts +++ b/packages/@aws-cdk/aws-cloudtrail/lib/index.ts @@ -3,7 +3,7 @@ import kms = require('@aws-cdk/aws-kms'); import logs = require('@aws-cdk/aws-logs'); import s3 = require('@aws-cdk/aws-s3'); import cdk = require('@aws-cdk/cdk'); -import { cloudformation, TrailArn } from './cloudtrail.generated'; +import { cloudformation } from './cloudtrail.generated'; // AWS::CloudTrail CloudFormation Resources: export * from './cloudtrail.generated'; @@ -121,9 +121,9 @@ export enum LogRetention { */ export class CloudTrail extends cdk.Construct { - public readonly cloudTrailArn: TrailArn; - private readonly cloudWatchLogsRoleArn?: cdk.Token; - private readonly cloudWatchLogsGroupArn?: cdk.Token; + public readonly cloudTrailArn: string; + private readonly cloudWatchLogsRoleArn?: string; + private readonly cloudWatchLogsGroupArn?: string; private eventSelectors: EventSelector[] = []; constructor(parent: cdk.Construct, name: string, props: CloudTrailProps = {}) { @@ -151,7 +151,7 @@ export class CloudTrail extends cdk.Construct { const logsRole = new iam.Role(this, 'LogsRole', {assumedBy: new cdk.ServicePrincipal(cloudTrailPrincipal) }); - const streamArn = new cdk.Arn(new cdk.FnConcat(this.cloudWatchLogsGroupArn, ":log-stream:*")); + const streamArn = `${this.cloudWatchLogsRoleArn}:log-stream:*`; logsRole.addToPolicy(new cdk.PolicyStatement() .addActions("logs:PutLogEvents", "logs:CreateLogStream") .addResource(streamArn)); diff --git a/packages/@aws-cdk/aws-cloudwatch/lib/alarm.ts b/packages/@aws-cdk/aws-cloudwatch/lib/alarm.ts index df7debeae9140..9dbbb2e6d5d0f 100644 --- a/packages/@aws-cdk/aws-cloudwatch/lib/alarm.ts +++ b/packages/@aws-cdk/aws-cloudwatch/lib/alarm.ts @@ -1,5 +1,5 @@ -import { Arn, Construct, Token } from '@aws-cdk/cdk'; -import { AlarmArn, cloudformation } from './cloudwatch.generated'; +import { Construct, Token } from '@aws-cdk/cdk'; +import { cloudformation } from './cloudwatch.generated'; import { HorizontalAnnotation } from './graph'; import { Dimension, Metric, Statistic, Unit } from './metric'; import { parseStatistic } from './util.statistic'; @@ -119,16 +119,16 @@ export class Alarm extends Construct { /** * ARN of this alarm */ - public readonly alarmArn: AlarmArn; + public readonly alarmArn: string; /** * The metric object this alarm was based on */ public readonly metric: Metric; - private alarmActions?: Arn[]; - private insufficientDataActions?: Arn[]; - private okActions?: Arn[]; + private alarmActionArns?: string[]; + private insufficientDataActionArns?: string[]; + private okActionArns?: string[]; /** * This metric as an annotation @@ -154,9 +154,9 @@ export class Alarm extends Construct { // Actions actionsEnabled: props.actionsEnabled, - alarmActions: new Token(() => this.alarmActions), - insufficientDataActions: new Token(() => this.insufficientDataActions), - okActions: new Token(() => this.okActions), + alarmActions: new Token(() => this.alarmActionArns), + insufficientDataActions: new Token(() => this.insufficientDataActionArns), + okActions: new Token(() => this.okActionArns), // Metric ...metricJson(props.metric) @@ -177,11 +177,11 @@ export class Alarm extends Construct { * Typically the ARN of an SNS topic or ARN of an AutoScaling policy. */ public onAlarm(...actions: IAlarmAction[]) { - if (this.alarmActions === undefined) { - this.alarmActions = []; + if (this.alarmActionArns === undefined) { + this.alarmActionArns = []; } - this.alarmActions.push(...actions.map(a => a.alarmActionArn)); + this.alarmActionArns.push(...actions.map(a => a.alarmActionArn)); } /** @@ -190,11 +190,11 @@ export class Alarm extends Construct { * Typically the ARN of an SNS topic or ARN of an AutoScaling policy. */ public onInsufficientData(...actions: IAlarmAction[]) { - if (this.insufficientDataActions === undefined) { - this.insufficientDataActions = []; + if (this.insufficientDataActionArns === undefined) { + this.insufficientDataActionArns = []; } - this.insufficientDataActions.push(...actions.map(a => a.alarmActionArn)); + this.insufficientDataActionArns.push(...actions.map(a => a.alarmActionArn)); } /** @@ -203,11 +203,11 @@ export class Alarm extends Construct { * Typically the ARN of an SNS topic or ARN of an AutoScaling policy. */ public onOk(...actions: IAlarmAction[]) { - if (this.okActions === undefined) { - this.okActions = []; + if (this.okActionArns === undefined) { + this.okActionArns = []; } - this.okActions.push(...actions.map(a => a.alarmActionArn)); + this.okActionArns.push(...actions.map(a => a.alarmActionArn)); } /** @@ -250,7 +250,7 @@ export interface IAlarmAction { /** * Return the ARN that should be used for a CloudWatch Alarm action */ - readonly alarmActionArn: Arn; + readonly alarmActionArn: string; } /** diff --git a/packages/@aws-cdk/aws-cloudwatch/lib/graph.ts b/packages/@aws-cdk/aws-cloudwatch/lib/graph.ts index ccb8e8bf73db6..91468f561e2fe 100644 --- a/packages/@aws-cdk/aws-cloudwatch/lib/graph.ts +++ b/packages/@aws-cdk/aws-cloudwatch/lib/graph.ts @@ -1,15 +1,9 @@ -import { AwsRegion, Token } from "@aws-cdk/cdk"; +import { AwsRegion } from "@aws-cdk/cdk"; import { Alarm } from "./alarm"; import { Metric } from "./metric"; import { parseStatistic } from './util.statistic'; import { ConcreteWidget } from "./widget"; -/** - * An AWS region - */ -export class Region extends Token { -} - /** * Basic properties for widgets that display metrics */ @@ -24,7 +18,7 @@ export interface MetricWidgetProps { * * @default Current region */ - region?: Region; + region?: string; /** * Width of the widget, in a grid of 24 units wide diff --git a/packages/@aws-cdk/aws-cloudwatch/test/test.alarm.ts b/packages/@aws-cdk/aws-cloudwatch/test/test.alarm.ts index 669d0e9e0ea4d..de6145e56668a 100644 --- a/packages/@aws-cdk/aws-cloudwatch/test/test.alarm.ts +++ b/packages/@aws-cdk/aws-cloudwatch/test/test.alarm.ts @@ -1,5 +1,5 @@ import { expect, haveResource } from '@aws-cdk/assert'; -import { Arn, Stack } from '@aws-cdk/cdk'; +import { Stack } from '@aws-cdk/cdk'; import { Test } from 'nodeunit'; import { Alarm, IAlarmAction, Metric } from '../lib'; diff --git a/packages/@aws-cdk/aws-codebuild/lib/project.ts b/packages/@aws-cdk/aws-codebuild/lib/project.ts index af4d2aaa92f45..b770ad2933a52 100644 --- a/packages/@aws-cdk/aws-codebuild/lib/project.ts +++ b/packages/@aws-cdk/aws-codebuild/lib/project.ts @@ -7,7 +7,7 @@ import kms = require('@aws-cdk/aws-kms'); import s3 = require('@aws-cdk/aws-s3'); import cdk = require('@aws-cdk/cdk'); import { BuildArtifacts, CodePipelineBuildArtifacts, NoBuildArtifacts } from './artifacts'; -import { cloudformation, ProjectArn, ProjectName } from './codebuild.generated'; +import { cloudformation } from './codebuild.generated'; import { CommonPipelineBuildActionProps, PipelineBuildAction } from './pipeline-actions'; import { BuildSource, NoSource } from './source'; @@ -26,7 +26,7 @@ export interface ProjectRefProps { * The human-readable name of the CodeBuild Project we're referencing. * The Project must be in the same account and region as the root Stack. */ - projectName: ProjectName; + projectName: string; } /** @@ -60,10 +60,10 @@ export abstract class ProjectRef extends cdk.Construct implements events.IEventR } /** The ARN of this Project. */ - public abstract readonly projectArn: ProjectArn; + public abstract readonly projectArn: string; /** The human-visible name of this Project. */ - public abstract readonly projectName: ProjectName; + public abstract readonly projectName: string; /** The IAM service Role of this Project. Undefined for imported Projects. */ public abstract readonly role?: iam.Role; @@ -76,7 +76,7 @@ export abstract class ProjectRef extends cdk.Construct implements events.IEventR */ public export(): ProjectRefProps { return { - projectName: new ProjectName(new cdk.Output(this, 'ProjectName', { value: this.projectName }).makeImportValue()), + projectName: new cdk.Output(this, 'ProjectName', { value: this.projectName }).makeImportValue().toString(), }; } @@ -276,7 +276,7 @@ export abstract class ProjectRef extends cdk.Construct implements events.IEventR /** * Allows using build projects as event rule targets. */ - public asEventRuleTarget(_ruleArn: events.RuleArn, _ruleId: string): events.EventRuleTargetProps { + public asEventRuleTarget(_ruleArn: string, _ruleId: string): events.EventRuleTargetProps { if (!this.eventsRole) { this.eventsRole = new iam.Role(this, 'EventsRole', { assumedBy: new cdk.ServicePrincipal('events.amazonaws.com') @@ -296,18 +296,19 @@ export abstract class ProjectRef extends cdk.Construct implements events.IEventR } class ImportedProjectRef extends ProjectRef { - public readonly projectArn: ProjectArn; - public readonly projectName: ProjectName; + public readonly projectArn: string; + public readonly projectName: string; public readonly role?: iam.Role = undefined; constructor(parent: cdk.Construct, name: string, props: ProjectRefProps) { super(parent, name); - this.projectArn = new ProjectArn(cdk.Arn.fromComponents({ + this.projectArn = cdk.ArnUtils.fromComponents({ service: 'codebuild', resource: 'project', resourceName: props.projectName, - })); + }); + this.projectName = props.projectName; } } @@ -427,12 +428,12 @@ export class Project extends ProjectRef { /** * The ARN of the project. */ - public readonly projectArn: ProjectArn; + public readonly projectArn: string; /** * The name of the project. */ - public readonly projectName: ProjectName; + public readonly projectName: string; private readonly source: BuildSource; private readonly buildImage: IBuildImage; @@ -521,14 +522,14 @@ export class Project extends ProjectRef { } private createLoggingPermission() { - const logGroupArn = cdk.Arn.fromComponents({ + const logGroupArn = cdk.ArnUtils.fromComponents({ service: 'logs', resource: 'log-group', sep: ':', - resourceName: new cdk.FnConcat('/aws/codebuild/', this.projectName), + resourceName: `/aws/codebuild/${this.projectName}`, }); - const logGroupStarArn = new cdk.Arn(new cdk.FnConcat(logGroupArn, ':*')); + const logGroupStarArn = `${logGroupArn}:*`; const p = new cdk.PolicyStatement(); p.allow(); diff --git a/packages/@aws-cdk/aws-codecommit/lib/repository.ts b/packages/@aws-cdk/aws-codecommit/lib/repository.ts index a92da69b20bbf..fd8a7bf5b2128 100644 --- a/packages/@aws-cdk/aws-codecommit/lib/repository.ts +++ b/packages/@aws-cdk/aws-codecommit/lib/repository.ts @@ -1,7 +1,7 @@ import actions = require('@aws-cdk/aws-codepipeline-api'); import events = require('@aws-cdk/aws-events'); import cdk = require('@aws-cdk/cdk'); -import { cloudformation, RepositoryArn, RepositoryName } from './codecommit.generated'; +import { cloudformation } from './codecommit.generated'; import { CommonPipelineSourceProps, PipelineSource } from './pipeline-action'; /** @@ -12,7 +12,7 @@ export interface RepositoryRefProps { * The name of an existing CodeCommit Repository that we are referencing. * Must be in the same account and region as the root Stack. */ - repositoryName: RepositoryName; + repositoryName: string; } /** @@ -39,10 +39,10 @@ export abstract class RepositoryRef extends cdk.Construct { } /** The ARN of this Repository. */ - public abstract readonly repositoryArn: RepositoryArn; + public abstract readonly repositoryArn: string; /** The human-visible name of this Repository. */ - public abstract readonly repositoryName: RepositoryName; + public abstract readonly repositoryName: string; /** * Exports this Repository. Allows the same Repository to be used in 2 different Stacks. @@ -51,7 +51,7 @@ export abstract class RepositoryRef extends cdk.Construct { */ public export(): RepositoryRefProps { return { - repositoryName: new RepositoryName(new cdk.Output(this, 'RepositoryName', { value: this.repositoryName }).makeImportValue()), + repositoryName: new cdk.Output(this, 'RepositoryName', { value: this.repositoryName }).makeImportValue().toString() }; } @@ -170,16 +170,16 @@ export abstract class RepositoryRef extends cdk.Construct { } class ImportedRepositoryRef extends RepositoryRef { - public readonly repositoryArn: RepositoryArn; - public readonly repositoryName: RepositoryName; + public readonly repositoryArn: string; + public readonly repositoryName: string; constructor(parent: cdk.Construct, name: string, props: RepositoryRefProps) { super(parent, name); - this.repositoryArn = new RepositoryArn(cdk.Arn.fromComponents({ + this.repositoryArn = cdk.ArnUtils.fromComponents({ service: 'codecommit', resource: props.repositoryName, - })); + }); this.repositoryName = props.repositoryName; } } diff --git a/packages/@aws-cdk/aws-codedeploy/lib/application.ts b/packages/@aws-cdk/aws-codedeploy/lib/application.ts index e64a5bff80b2c..0c207e799e110 100644 --- a/packages/@aws-cdk/aws-codedeploy/lib/application.ts +++ b/packages/@aws-cdk/aws-codedeploy/lib/application.ts @@ -1,7 +1,5 @@ import cdk = require('@aws-cdk/cdk'); -import { ApplicationName, cloudformation } from './codedeploy.generated'; - -export class ApplicationArn extends cdk.Arn {} +import { cloudformation } from './codedeploy.generated'; /** * Properties of a reference to a CodeDeploy EC2/on-premise Application. @@ -14,7 +12,7 @@ export interface ServerApplicationRefProps { * The physical, human-readable name of the CodeDeploy EC2/on-premise Application we're referencing. * The Application must be in the same account and region as the root Stack. */ - applicationName: ApplicationName; + applicationName: string; } /** @@ -41,20 +39,20 @@ export abstract class ServerApplicationRef extends cdk.Construct { return new ImportedServerApplicationRef(parent, id, props); } - public abstract readonly applicationArn: ApplicationArn; + public abstract readonly applicationArn: string; - public abstract readonly applicationName: ApplicationName; + public abstract readonly applicationName: string; public export(): ServerApplicationRefProps { return { - applicationName: new ApplicationName(new cdk.Output(this, 'ApplicationName', { value: this.applicationName }).makeImportValue()), + applicationName: new cdk.Output(this, 'ApplicationName', { value: this.applicationName }).makeImportValue().toString() }; } } class ImportedServerApplicationRef extends ServerApplicationRef { - public readonly applicationArn: ApplicationArn; - public readonly applicationName: ApplicationName; + public readonly applicationArn: string; + public readonly applicationName: string; constructor(parent: cdk.Construct, id: string, props: ServerApplicationRefProps) { super(parent, id); @@ -80,8 +78,8 @@ export interface ServerApplicationProps { * A CodeDeploy Application that deploys to EC2/on-premise instances. */ export class ServerApplication extends ServerApplicationRef { - public readonly applicationArn: ApplicationArn; - public readonly applicationName: ApplicationName; + public readonly applicationArn: string; + public readonly applicationName: string; constructor(parent: cdk.Construct, id: string, props?: ServerApplicationProps) { super(parent, id); @@ -96,8 +94,8 @@ export class ServerApplication extends ServerApplicationRef { } } -function applicationName2Arn(applicationName: ApplicationName): ApplicationArn { - return cdk.Arn.fromComponents({ +function applicationName2Arn(applicationName: string): string { + return cdk.ArnUtils.fromComponents({ service: 'codedeploy', resource: 'application', resourceName: applicationName, diff --git a/packages/@aws-cdk/aws-codedeploy/lib/deployment-group.ts b/packages/@aws-cdk/aws-codedeploy/lib/deployment-group.ts index e4cb8404cd3dc..7e8f0bcdaeed0 100644 --- a/packages/@aws-cdk/aws-codedeploy/lib/deployment-group.ts +++ b/packages/@aws-cdk/aws-codedeploy/lib/deployment-group.ts @@ -1,9 +1,7 @@ import cdk = require("@aws-cdk/cdk"); import iam = require("../../aws-iam/lib/role"); import { ServerApplication, ServerApplicationRef } from "./application"; -import { ApplicationName, cloudformation, DeploymentGroupName } from './codedeploy.generated'; - -export class DeploymentGroupArn extends cdk.Arn {} +import { cloudformation } from './codedeploy.generated'; /** * Properties of a reference to a CodeDeploy EC2/on-premise Deployment Group. @@ -22,7 +20,7 @@ export interface ServerDeploymentGroupRefProps { * The physical, human-readable name of the CodeDeploy EC2/on-premise Deployment Group * that we are referencing. */ - deploymentGroupName: DeploymentGroupName; + deploymentGroupName: string; } /** @@ -50,23 +48,21 @@ export abstract class ServerDeploymentGroupRef extends cdk.Construct { } public abstract readonly application: ServerApplicationRef; - public abstract readonly deploymentGroupName: DeploymentGroupName; - public abstract readonly deploymentGroupArn: DeploymentGroupArn; + public abstract readonly deploymentGroupName: string; + public abstract readonly deploymentGroupArn: string; public export(): ServerDeploymentGroupRefProps { return { application: this.application, - deploymentGroupName: new DeploymentGroupName(new cdk.Output(this, 'DeploymentGroupName', { - value: this.deploymentGroupName - }).makeImportValue()), + deploymentGroupName: new cdk.Output(this, 'DeploymentGroupName', { value: this.deploymentGroupName }).makeImportValue().toString() }; } } class ImportedServerDeploymentGroupRef extends ServerDeploymentGroupRef { public readonly application: ServerApplicationRef; - public readonly deploymentGroupName: DeploymentGroupName; - public readonly deploymentGroupArn: DeploymentGroupArn; + public readonly deploymentGroupName: string; + public readonly deploymentGroupArn: string; constructor(parent: cdk.Construct, id: string, props: ServerDeploymentGroupRefProps) { super(parent, id); @@ -108,8 +104,8 @@ export interface ServerDeploymentGroupProps { export class ServerDeploymentGroup extends ServerDeploymentGroupRef { public readonly application: ServerApplicationRef; public readonly role: iam.Role; - public readonly deploymentGroupArn: DeploymentGroupArn; - public readonly deploymentGroupName: DeploymentGroupName; + public readonly deploymentGroupArn: string; + public readonly deploymentGroupName: string; constructor(parent: cdk.Construct, id: string, props?: ServerDeploymentGroupProps) { super(parent, id); @@ -133,12 +129,11 @@ export class ServerDeploymentGroup extends ServerDeploymentGroupRef { } } -function deploymentGroupName2Arn(applicationName: ApplicationName, - deploymentGroupName: DeploymentGroupName): DeploymentGroupArn { - return cdk.Arn.fromComponents({ +function deploymentGroupName2Arn(applicationName: string, deploymentGroupName: string): string { + return cdk.ArnUtils.fromComponents({ service: 'codedeploy', resource: 'deploymentgroup', - resourceName: new cdk.FnJoin('/', [applicationName, deploymentGroupName]), + resourceName: `${applicationName}/${deploymentGroupName}`, sep: ':', }); } diff --git a/packages/@aws-cdk/aws-codedeploy/lib/pipeline-action.ts b/packages/@aws-cdk/aws-codedeploy/lib/pipeline-action.ts index 3c70561691b8c..e565504a8af8c 100644 --- a/packages/@aws-cdk/aws-codedeploy/lib/pipeline-action.ts +++ b/packages/@aws-cdk/aws-codedeploy/lib/pipeline-action.ts @@ -43,7 +43,7 @@ export class PipelineDeployAction extends actions.DeployAction { // permissions, based on: // https://docs.aws.amazon.com/codedeploy/latest/userguide/auth-and-access-control-permissions-reference.html - const applicationArn = cdk.Arn.fromComponents({ + const applicationArn = cdk.ArnUtils.fromComponents({ service: 'codedeploy', resource: 'application', resourceName: props.applicationName, @@ -56,7 +56,7 @@ export class PipelineDeployAction extends actions.DeployAction { 'codedeploy:RegisterApplicationRevision', )); - const deploymentGroupArn = cdk.Arn.fromComponents({ + const deploymentGroupArn = cdk.ArnUtils.fromComponents({ service: 'codedeploy', resource: 'deploymentgroup', resourceName: `${props.applicationName}/${props.deploymentGroupName}`, @@ -69,7 +69,7 @@ export class PipelineDeployAction extends actions.DeployAction { 'codedeploy:GetDeployment', )); - const deployConfigArn = cdk.Arn.fromComponents({ + const deployConfigArn = cdk.ArnUtils.fromComponents({ service: 'codedeploy', resource: 'deploymentconfig', resourceName: '*', diff --git a/packages/@aws-cdk/aws-codepipeline-api/lib/action.ts b/packages/@aws-cdk/aws-codepipeline-api/lib/action.ts index ef00f15384163..880d7101b9221 100644 --- a/packages/@aws-cdk/aws-codepipeline-api/lib/action.ts +++ b/packages/@aws-cdk/aws-codepipeline-api/lib/action.ts @@ -48,7 +48,7 @@ export interface IStage { /** * The ARN of the Pipeline. */ - readonly pipelineArn: cdk.Arn; + readonly pipelineArn: string; /** * The service Role of the Pipeline. diff --git a/packages/@aws-cdk/aws-codepipeline-api/lib/artifact.ts b/packages/@aws-cdk/aws-codepipeline-api/lib/artifact.ts index 6663e5375effa..c67698204f9c4 100644 --- a/packages/@aws-cdk/aws-codepipeline-api/lib/artifact.ts +++ b/packages/@aws-cdk/aws-codepipeline-api/lib/artifact.ts @@ -1,24 +1,6 @@ -import { Construct, Token } from "@aws-cdk/cdk"; +import { CloudFormationToken, Construct } from "@aws-cdk/cdk"; import { Action } from "./action"; -/** - * @link https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/continuous-delivery-codepipeline-parameter-override-functions.html - */ -export class ArtifactAttribute extends Token { - constructor(artifact: Artifact, attributeName: string) { - super(() => ({ 'Fn::GetArtifactAtt': [artifact.name, attributeName] })); - } -} - -/** - * @link https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/continuous-delivery-codepipeline-parameter-override-functions.html - */ -export class ArtifactGetParam extends Token { - constructor(artifact: Artifact, jsonFile: string, keyName: string) { - super(() => ({ 'Fn::GetParam': [artifact.name, jsonFile, keyName] })); - } -} - /** * An output artifact of an action. Artifacts can be used as input by some actions. */ @@ -40,7 +22,7 @@ export class Artifact extends Construct { * The artifact attribute for the name of the S3 bucket where the artifact is stored. */ public get bucketName() { - return new ArtifactAttribute(this, 'BucketName'); + return artifactAttribute(this, 'BucketName'); } /** @@ -48,7 +30,7 @@ export class Artifact extends Construct { * generated by AWS CodePipeline, such as 1ABCyZZ.zip. */ public get objectKey() { - return new ArtifactAttribute(this, 'ObjectKey'); + return artifactAttribute(this, 'ObjectKey'); } /** @@ -56,7 +38,7 @@ export class Artifact extends Construct { * such as https://s3-us-west-2.amazonaws.com/artifactstorebucket-yivczw8jma0c/test/TemplateSo/1ABCyZZ.zip. */ public get url() { - return new ArtifactAttribute(this, 'URL'); + return artifactAttribute(this, 'URL'); } /** @@ -65,7 +47,7 @@ export class Artifact extends Construct { * @param keyName The hash key. */ public getParam(jsonFile: string, keyName: string) { - return new ArtifactGetParam(this, jsonFile, keyName); + return artifactGetParam(this, jsonFile, keyName); } public toString() { @@ -88,3 +70,11 @@ export class ArtifactPath { return `${this.artifact.name}::${this.fileName}`; } } + +function artifactAttribute(artifact: Artifact, attributeName: string) { + return new CloudFormationToken(() => ({ 'Fn::GetArtifactAtt': [artifact.name, attributeName] })).toString(); +} + +function artifactGetParam(artifact: Artifact, jsonFile: string, keyName: string) { + return new CloudFormationToken(() => ({ 'Fn::GetParam': [artifact.name, jsonFile, keyName] })).toString(); +} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-codepipeline/lib/pipeline.ts b/packages/@aws-cdk/aws-codepipeline/lib/pipeline.ts index ffe8b6f01c214..747c96c6e615b 100644 --- a/packages/@aws-cdk/aws-codepipeline/lib/pipeline.ts +++ b/packages/@aws-cdk/aws-codepipeline/lib/pipeline.ts @@ -4,14 +4,9 @@ import iam = require('@aws-cdk/aws-iam'); import s3 = require('@aws-cdk/aws-s3'); import cdk = require('@aws-cdk/cdk'); import util = require('@aws-cdk/util'); -import { cloudformation, PipelineName, PipelineVersion } from './codepipeline.generated'; +import { cloudformation } from './codepipeline.generated'; import { Stage } from './stage'; -/** - * The ARN of a pipeline - */ -export class PipelineArn extends cdk.Arn { } - export interface PipelineProps { /** * The S3 bucket used by this Pipeline to store artifacts. @@ -59,17 +54,17 @@ export class Pipeline extends cdk.Construct implements events.IEventRuleTarget { /** * ARN of this pipeline */ - public readonly pipelineArn: PipelineArn; + public readonly pipelineArn: string; /** * The name of the pipeline */ - public readonly pipelineName: PipelineName; + public readonly pipelineName: string; /** * The version of the pipeline */ - public readonly pipelineVersion: PipelineVersion; + public readonly pipelineVersion: string; /** * Bucket used to store output artifacts @@ -115,10 +110,10 @@ export class Pipeline extends cdk.Construct implements events.IEventRuleTarget { this.pipelineVersion = codePipeline.pipelineVersion; // Does not expose a Fn::GetAtt for the ARN so we'll have to make it ourselves - this.pipelineArn = new PipelineArn(cdk.Arn.fromComponents({ + this.pipelineArn = cdk.ArnUtils.fromComponents({ service: 'codepipeline', resource: this.pipelineName - })); + }); } /** @@ -138,7 +133,7 @@ export class Pipeline extends cdk.Construct implements events.IEventRuleTarget { * rule.addTarget(pipeline); * */ - public asEventRuleTarget(_ruleArn: events.RuleArn, _ruleId: string): events.EventRuleTargetProps { + public asEventRuleTarget(_ruleArn: string, _ruleId: string): events.EventRuleTargetProps { // the first time the event rule target is retrieved, we define an IAM // role assumable by the CloudWatch events service which is allowed to // start the execution of this pipeline. no need to define more than one diff --git a/packages/@aws-cdk/aws-codepipeline/lib/stage.ts b/packages/@aws-cdk/aws-codepipeline/lib/stage.ts index b2094f0ff3127..c3b63484d3d1c 100644 --- a/packages/@aws-cdk/aws-codepipeline/lib/stage.ts +++ b/packages/@aws-cdk/aws-codepipeline/lib/stage.ts @@ -83,7 +83,7 @@ export class Stage extends cdk.Construct implements actions.IStage { return rule; } - public get pipelineArn(): cdk.Arn { + public get pipelineArn(): string { return this.pipeline.pipelineArn; } diff --git a/packages/@aws-cdk/aws-dynamodb/lib/table.ts b/packages/@aws-cdk/aws-dynamodb/lib/table.ts index 19d80913e98bc..db954db64d1c1 100644 --- a/packages/@aws-cdk/aws-dynamodb/lib/table.ts +++ b/packages/@aws-cdk/aws-dynamodb/lib/table.ts @@ -1,7 +1,7 @@ import { cloudformation as applicationautoscaling } from '@aws-cdk/aws-applicationautoscaling'; import { Role } from '@aws-cdk/aws-iam'; import { Construct, PolicyStatement, PolicyStatementEffect, ServicePrincipal } from '@aws-cdk/cdk'; -import { cloudformation as dynamodb, TableArn, TableName, TableStreamArn } from './dynamodb.generated'; +import { cloudformation as dynamodb } from './dynamodb.generated'; const HASH_KEY_TYPE = 'HASH'; const RANGE_KEY_TYPE = 'RANGE'; @@ -106,9 +106,9 @@ export interface AutoScalingProps { * Provides a DynamoDB table. */ export class Table extends Construct { - public readonly tableArn: TableArn; - public readonly tableName: TableName; - public readonly tableStreamArn: TableStreamArn; + public readonly tableArn: string; + public readonly tableName: string; + public readonly tableStreamArn: string; private readonly table: dynamodb.TableResource; @@ -138,7 +138,7 @@ export class Table extends Construct { if (props.tableName) { this.addMetadata('aws:cdk:hasPhysicalName', props.tableName); } this.tableArn = this.table.tableArn; - this.tableName = this.table.ref; + this.tableName = this.table.tableName; this.tableStreamArn = this.table.tableStreamArn; if (props.readAutoScaling) { diff --git a/packages/@aws-cdk/aws-ec2/lib/security-group-rule.ts b/packages/@aws-cdk/aws-ec2/lib/security-group-rule.ts index 013f30b6d446a..9dbf8af85c5a1 100644 --- a/packages/@aws-cdk/aws-ec2/lib/security-group-rule.ts +++ b/packages/@aws-cdk/aws-ec2/lib/security-group-rule.ts @@ -1,4 +1,3 @@ -import { Token } from "@aws-cdk/cdk"; import { Connections, IConnectable } from "./connections"; /** @@ -162,7 +161,7 @@ export class TcpPort implements IPortRange { export class TcpPortFromAttribute implements IPortRange { public readonly canInlineRule = false; - constructor(private readonly port: Token) { + constructor(private readonly port: string) { } public toRuleJSON(): any { diff --git a/packages/@aws-cdk/aws-ec2/lib/security-group.ts b/packages/@aws-cdk/aws-ec2/lib/security-group.ts index 88aceba456bf1..07d23af92f456 100644 --- a/packages/@aws-cdk/aws-ec2/lib/security-group.ts +++ b/packages/@aws-cdk/aws-ec2/lib/security-group.ts @@ -1,6 +1,6 @@ import { Construct, Output, Token } from '@aws-cdk/cdk'; import { Connections, IConnectable } from './connections'; -import { cloudformation, SecurityGroupId, SecurityGroupName, SecurityGroupVpcId } from './ec2.generated'; +import { cloudformation } from './ec2.generated'; import { IPortRange, ISecurityGroupRule } from './security-group-rule'; import { slugify } from './util'; import { VpcNetworkRef } from './vpc-ref'; @@ -9,7 +9,7 @@ export interface SecurityGroupRefProps { /** * ID of security group */ - securityGroupId: SecurityGroupId; + securityGroupId: string; } /** @@ -23,7 +23,7 @@ export abstract class SecurityGroupRef extends Construct implements ISecurityGro return new ImportedSecurityGroup(parent, id, props); } - public abstract readonly securityGroupId: SecurityGroupId; + public abstract readonly securityGroupId: string; public readonly canInlineRule = false; public readonly connections = new Connections({ securityGroup: this }); @@ -63,7 +63,7 @@ export abstract class SecurityGroupRef extends Construct implements ISecurityGro */ public export(): SecurityGroupRefProps { return { - securityGroupId: new SecurityGroupId(new Output(this, 'SecurityGroupId', { value: this.securityGroupId }).makeImportValue()) + securityGroupId: new Output(this, 'SecurityGroupId', { value: this.securityGroupId }).makeImportValue().toString() }; } @@ -106,17 +106,17 @@ export class SecurityGroup extends SecurityGroupRef { /** * An attribute that represents the security group name. */ - public readonly groupName: SecurityGroupName; + public readonly groupName: string; /** * An attribute that represents the physical VPC ID this security group is part of. */ - public readonly vpcId: SecurityGroupVpcId; + public readonly vpcId: string; /** * The ID of the security group */ - public readonly securityGroupId: SecurityGroupId; + public readonly securityGroupId: string; private readonly securityGroup: cloudformation.SecurityGroupResource; private readonly directIngressRules: cloudformation.SecurityGroupResource.IngressProperty[] = []; @@ -135,7 +135,7 @@ export class SecurityGroup extends SecurityGroupRef { }); this.securityGroupId = this.securityGroup.securityGroupId; - this.groupName = this.securityGroup.ref; + this.groupName = this.securityGroup.securityGroupName; this.vpcId = this.securityGroup.securityGroupVpcId; } @@ -243,7 +243,7 @@ export interface ConnectionRule { * A SecurityGroup that hasn't been created here */ class ImportedSecurityGroup extends SecurityGroupRef { - public readonly securityGroupId: SecurityGroupId; + public readonly securityGroupId: string; constructor(parent: Construct, name: string, props: SecurityGroupRefProps) { super(parent, name); diff --git a/packages/@aws-cdk/aws-ec2/lib/util.ts b/packages/@aws-cdk/aws-ec2/lib/util.ts index e577665bc1141..d8e8f84f9b809 100644 --- a/packages/@aws-cdk/aws-ec2/lib/util.ts +++ b/packages/@aws-cdk/aws-ec2/lib/util.ts @@ -1,5 +1,4 @@ import cdk = require('@aws-cdk/cdk'); -import { SubnetId } from './ec2.generated'; import { SubnetType, VpcSubnetRef } from "./vpc-ref"; /** @@ -40,7 +39,7 @@ export function subnetId(name: string, i: number) { * Helper class to export/import groups of subnets */ export class ExportSubnetGroup { - public readonly ids?: SubnetId[]; + public readonly ids?: string[]; public readonly names?: string[]; private readonly groups: number; @@ -63,9 +62,9 @@ export class ExportSubnetGroup { this.names = this.exportNames(); } - private exportIds(parent: cdk.Construct, name: string): SubnetId[] | undefined { + private exportIds(parent: cdk.Construct, name: string): string[] | undefined { if (this.subnets.length === 0) { return undefined; } - return new cdk.StringListOutput(parent, name, { values: this.subnets.map(s => s.subnetId) }).makeImportValues().map(x => new SubnetId(x)); + return new cdk.StringListOutput(parent, name, { values: this.subnets.map(s => s.subnetId) }).makeImportValues().map(x => x.toString()); } /** @@ -94,12 +93,12 @@ export class ExportSubnetGroup { } export class ImportSubnetGroup { - private readonly subnetIds: SubnetId[]; + private readonly subnetIds: string[]; private readonly names: string[]; private readonly groups: number; constructor( - subnetIds: SubnetId[] | undefined, + subnetIds: string[] | undefined, names: string[] | undefined, type: SubnetType, private readonly availabilityZones: string[], diff --git a/packages/@aws-cdk/aws-ec2/lib/vpc-ref.ts b/packages/@aws-cdk/aws-ec2/lib/vpc-ref.ts index 868eacfdd771d..b05f07dbb9f7a 100644 --- a/packages/@aws-cdk/aws-ec2/lib/vpc-ref.ts +++ b/packages/@aws-cdk/aws-ec2/lib/vpc-ref.ts @@ -1,5 +1,4 @@ import { Construct, IDependable, Output } from "@aws-cdk/cdk"; -import { SubnetId, VPCId } from "./ec2.generated"; import { ExportSubnetGroup, ImportSubnetGroup, subnetName } from './util'; /** @@ -85,7 +84,7 @@ export abstract class VpcNetworkRef extends Construct implements IDependable { /** * Identifier for this VPC */ - public abstract readonly vpcId: VPCId; + public abstract readonly vpcId: string; /** * List of public subnets in this VPC @@ -149,7 +148,7 @@ export abstract class VpcNetworkRef extends Construct implements IDependable { const iso = new ExportSubnetGroup(this, 'IsolatedSubnetIDs', this.isolatedSubnets, SubnetType.Isolated, this.availabilityZones.length); return { - vpcId: new VPCId(new Output(this, 'VpcId', { value: this.vpcId }).makeImportValue()), + vpcId: new Output(this, 'VpcId', { value: this.vpcId }).makeImportValue().toString(), availabilityZones: this.availabilityZones, publicSubnetIds: pub.ids, publicSubnetNames: pub.names, @@ -168,7 +167,7 @@ class ImportedVpcNetwork extends VpcNetworkRef { /** * Identifier for this VPC */ - public readonly vpcId: VPCId; + public readonly vpcId: string; /** * List of public subnets in this VPC @@ -215,7 +214,7 @@ export interface VpcNetworkRefProps { /** * VPC's identifier */ - vpcId: VPCId; + vpcId: string; /** * List of availability zones for the subnets in this VPC. @@ -227,7 +226,7 @@ export interface VpcNetworkRefProps { * * Must be undefined or match the availability zones in length and order. */ - publicSubnetIds?: SubnetId[]; + publicSubnetIds?: string[]; /** * List of names for the public subnets @@ -241,7 +240,7 @@ export interface VpcNetworkRefProps { * * Must be undefined or match the availability zones in length and order. */ - privateSubnetIds?: SubnetId[]; + privateSubnetIds?: string[]; /** * List of names for the private subnets @@ -255,7 +254,7 @@ export interface VpcNetworkRefProps { * * Must be undefined or match the availability zones in length and order. */ - isolatedSubnetIds?: SubnetId[]; + isolatedSubnetIds?: string[]; /** * List of names for the isolated subnets @@ -281,7 +280,7 @@ export abstract class VpcSubnetRef extends Construct implements IDependable { /** * The subnetId for this particular subnet */ - public abstract readonly subnetId: SubnetId; + public abstract readonly subnetId: string; /** * Parts of this VPC subnet @@ -301,7 +300,7 @@ class ImportedVpcSubnet extends VpcSubnetRef { /** * The subnetId for this particular subnet */ - public readonly subnetId: SubnetId; + public readonly subnetId: string; constructor(parent: Construct, name: string, props: VpcSubnetRefProps) { super(parent, name); @@ -320,5 +319,5 @@ export interface VpcSubnetRefProps { /** * The subnetId for this particular subnet */ - subnetId: SubnetId; + subnetId: string; } diff --git a/packages/@aws-cdk/aws-ec2/lib/vpc.ts b/packages/@aws-cdk/aws-ec2/lib/vpc.ts index 0e9ef7a068b79..07181f641e01b 100644 --- a/packages/@aws-cdk/aws-ec2/lib/vpc.ts +++ b/packages/@aws-cdk/aws-ec2/lib/vpc.ts @@ -1,6 +1,6 @@ import cdk = require('@aws-cdk/cdk'); import { Obj } from '@aws-cdk/util'; -import { cloudformation, SubnetId, VPCId } from './ec2.generated'; +import { cloudformation } from './ec2.generated'; import { NetworkBuilder } from './network-util'; import { DEFAULT_SUBNET_NAME, subnetId } from './util'; import { SubnetType, VpcNetworkRef, VpcSubnetRef } from './vpc-ref'; @@ -205,7 +205,7 @@ export class VpcNetwork extends VpcNetworkRef implements cdk.ITaggable { /** * Identifier for this VPC */ - public readonly vpcId: VPCId; + public readonly vpcId: string; /** * List of public subnets in this VPC @@ -252,7 +252,7 @@ export class VpcNetwork extends VpcNetworkRef implements cdk.ITaggable { /** * Mapping of NatGateway by AZ */ - private natGatewayByAZ: Obj = {}; + private natGatewayByAZ: Obj = {}; /** * Subnet configurations for this VPC @@ -298,7 +298,7 @@ export class VpcNetwork extends VpcNetworkRef implements cdk.ITaggable { this.availabilityZones = this.availabilityZones.slice(0, props.maxAZs); } - this.vpcId = this.resource.ref; + this.vpcId = this.resource.vpcId; this.dependencyElements.push(this.resource); this.subnetConfiguration = ifUndefined(props.subnetConfiguration, VpcNetwork.DEFAULT_SUBNETS); @@ -341,9 +341,9 @@ export class VpcNetwork extends VpcNetworkRef implements cdk.ITaggable { } /** - * @returns {Token} The IPv4 CidrBlock as returned by the VPC + * @returns The IPv4 CidrBlock as returned by the VPC */ - public get cidr(): cdk.Token { + public get cidr(): string { return this.resource.getAtt("CidrBlock"); } @@ -421,7 +421,7 @@ export interface VpcSubnetProps { /** * The VPC which this subnet is part of */ - vpcId: cdk.Token; + vpcId: string; /** * The CIDR notation for this subnet @@ -454,7 +454,7 @@ export class VpcSubnet extends VpcSubnetRef implements cdk.ITaggable { /** * The subnetId for this particular subnet */ - public readonly subnetId: SubnetId; + public readonly subnetId: string; /** * Manage tags for Construct and propagate to children @@ -464,7 +464,7 @@ export class VpcSubnet extends VpcSubnetRef implements cdk.ITaggable { /** * The routeTableId attached to this subnet. */ - private readonly routeTableId: cdk.Token; + private readonly routeTableId: string; constructor(parent: cdk.Construct, name: string, props: VpcSubnetProps) { super(parent, name); @@ -479,7 +479,7 @@ export class VpcSubnet extends VpcSubnetRef implements cdk.ITaggable { mapPublicIpOnLaunch: props.mapPublicIpOnLaunch, tags: this.tags, }); - this.subnetId = subnet.ref; + this.subnetId = subnet.subnetVpcId; const table = new cloudformation.RouteTableResource(this, 'RouteTable', { vpcId: props.vpcId, tags: new cdk.TagManager(this), @@ -495,7 +495,7 @@ export class VpcSubnet extends VpcSubnetRef implements cdk.ITaggable { this.dependencyElements.push(subnet, table, routeAssoc); } - protected addDefaultRouteToNAT(natGatewayId: cdk.Token) { + protected addDefaultRouteToNAT(natGatewayId: string) { new cloudformation.RouteResource(this, `DefaultRoute`, { routeTableId: this.routeTableId, destinationCidrBlock: '0.0.0.0/0', @@ -503,7 +503,7 @@ export class VpcSubnet extends VpcSubnetRef implements cdk.ITaggable { }); } - protected addDefaultRouteToIGW(gatewayId: cdk.Token) { + protected addDefaultRouteToIGW(gatewayId: string) { new cloudformation.RouteResource(this, `DefaultRoute`, { routeTableId: this.routeTableId, destinationCidrBlock: '0.0.0.0/0', @@ -523,7 +523,7 @@ export class VpcPublicSubnet extends VpcSubnet { /** * Create a default route that points to a passed IGW */ - public addDefaultIGWRouteEntry(gatewayId: cdk.Token) { + public addDefaultIGWRouteEntry(gatewayId: string) { this.addDefaultRouteToIGW(gatewayId); } @@ -556,7 +556,7 @@ export class VpcPrivateSubnet extends VpcSubnet { /** * Adds an entry to this subnets route table that points to the passed NATGatwayId */ - public addDefaultNatRouteEntry(natGatewayId: cdk.Token) { + public addDefaultNatRouteEntry(natGatewayId: string) { this.addDefaultRouteToNAT(natGatewayId); } } diff --git a/packages/@aws-cdk/aws-ec2/test/test.connections.ts b/packages/@aws-cdk/aws-ec2/test/test.connections.ts index c6cbbb6ae7d40..aedb7330c1b6b 100644 --- a/packages/@aws-cdk/aws-ec2/test/test.connections.ts +++ b/packages/@aws-cdk/aws-ec2/test/test.connections.ts @@ -1,7 +1,7 @@ import { expect, haveResource } from '@aws-cdk/assert'; import { Stack } from '@aws-cdk/cdk'; import { Test } from 'nodeunit'; -import { Connections, IConnectable, SecurityGroup, SecurityGroupId, SecurityGroupRef, TcpAllPorts, TcpPort, VpcNetwork } from '../lib'; +import { Connections, IConnectable, SecurityGroup, SecurityGroupRef, TcpAllPorts, TcpPort, VpcNetwork } from '../lib'; export = { 'peering between two security groups does not recursive infinitely'(test: Test) { @@ -29,7 +29,7 @@ export = { const sg1 = new SecurityGroup(stack, 'SomeSecurityGroup', { vpc }); const somethingConnectable = new SomethingConnectable(new Connections({ securityGroup: sg1 })); - const securityGroup = SecurityGroupRef.import(stack, 'ImportedSG', { securityGroupId: new SecurityGroupId('sg-12345') }); + const securityGroup = SecurityGroupRef.import(stack, 'ImportedSG', { securityGroupId: 'sg-12345' }); // WHEN somethingConnectable.connections.allowTo(securityGroup, new TcpAllPorts(), 'Connect there'); diff --git a/packages/@aws-cdk/aws-ec2/test/test.vpc.ts b/packages/@aws-cdk/aws-ec2/test/test.vpc.ts index 0dcd81f14876c..459ab504462a5 100644 --- a/packages/@aws-cdk/aws-ec2/test/test.vpc.ts +++ b/packages/@aws-cdk/aws-ec2/test/test.vpc.ts @@ -10,7 +10,7 @@ export = { "vpc.vpcId returns a token to the VPC ID"(test: Test) { const stack = getTestStack(); const vpc = new VpcNetwork(stack, 'TheVPC'); - test.deepEqual(vpc.vpcId.resolve(), {Ref: 'TheVPC92636AB0' } ); + test.deepEqual(resolve(vpc.vpcId), {Ref: 'TheVPC92636AB0' } ); test.done(); }, @@ -68,7 +68,7 @@ export = { const zones = new AvailabilityZoneProvider(stack).availabilityZones.length; test.equal(vpc.publicSubnets.length, zones); test.equal(vpc.privateSubnets.length, zones); - test.deepEqual(vpc.vpcId.resolve(), { Ref: 'TheVPC92636AB0' }); + test.deepEqual(resolve(vpc.vpcId), { Ref: 'TheVPC92636AB0' }); test.done(); }, diff --git a/packages/@aws-cdk/aws-ecr/lib/repository-ref.ts b/packages/@aws-cdk/aws-ecr/lib/repository-ref.ts index 8683257096320..509f90ad47adf 100644 --- a/packages/@aws-cdk/aws-ecr/lib/repository-ref.ts +++ b/packages/@aws-cdk/aws-ecr/lib/repository-ref.ts @@ -38,19 +38,13 @@ export abstract class RepositoryRef extends cdk.Construct { /** * The URI of the repository, for use in Docker/image references */ - public get repositoryUri(): RepositoryUri { + public get repositoryUri(): string { // Calculate this from the ARN const parts = cdk.ArnUtils.parse(this.repositoryArn); - return new RepositoryUri(`${parts.account}.dkr.ecr.${parts.region}.amazonaws.com/${parts.resourceName}`); + return `${parts.account}.dkr.ecr.${parts.region}.amazonaws.com/${parts.resourceName}`; } } -/** - * URI of a repository - */ -export class RepositoryUri extends cdk.CloudFormationToken { -} - export interface RepositoryRefProps { repositoryArn: string; } diff --git a/packages/@aws-cdk/aws-elasticloadbalancing/lib/load-balancer.ts b/packages/@aws-cdk/aws-elasticloadbalancing/lib/load-balancer.ts index cb5e1bb42a6c6..b3677bce52a25 100644 --- a/packages/@aws-cdk/aws-elasticloadbalancing/lib/load-balancer.ts +++ b/packages/@aws-cdk/aws-elasticloadbalancing/lib/load-balancer.ts @@ -159,7 +159,7 @@ export interface LoadBalancerListener { /** * ID of SSL certificate */ - sslCertificateId?: cdk.Arn; + sslCertificateId?: string; /** * Allow connections to the load balancer from the given set of connection peers diff --git a/packages/@aws-cdk/aws-events/lib/event-pattern.ts b/packages/@aws-cdk/aws-events/lib/event-pattern.ts index 5e61080ce0055..52828cd9c5809 100644 --- a/packages/@aws-cdk/aws-events/lib/event-pattern.ts +++ b/packages/@aws-cdk/aws-events/lib/event-pattern.ts @@ -1,5 +1,3 @@ -import { Arn } from "@aws-cdk/cdk"; - /** * Events in Amazon CloudWatch Events are represented as JSON objects. For more * information about JSON objects, see RFC 7159. @@ -91,7 +89,7 @@ export interface EventPattern { * Auto Scaling groups, but API calls with AWS CloudTrail do not include * resource ARNs. */ - resources?: Arn[]; + resources?: string[]; /** * A JSON object, whose content is at the discretion of the service diff --git a/packages/@aws-cdk/aws-events/lib/target.ts b/packages/@aws-cdk/aws-events/lib/target.ts index 72a14cf005e39..ff9434be115fc 100644 --- a/packages/@aws-cdk/aws-events/lib/target.ts +++ b/packages/@aws-cdk/aws-events/lib/target.ts @@ -1,5 +1,3 @@ -import iam = require('@aws-cdk/aws-iam'); -import cdk = require('@aws-cdk/cdk'); import { cloudformation } from './events.generated'; export interface EventRuleTargetProps { @@ -13,7 +11,7 @@ export interface EventRuleTargetProps { /** * The Amazon Resource Name (ARN) of the target. */ - arn: cdk.Arn; + arn: string; /** * The Amazon Resource Name (ARN) of the AWS Identity and Access Management @@ -21,7 +19,7 @@ export interface EventRuleTargetProps { * triggers multiple targets, you can use a different IAM role for each * target. */ - roleArn?: iam.RoleArn; + roleArn?: string; /** * The Amazon ECS task definition and task count to use, if the event target diff --git a/packages/@aws-cdk/aws-events/test/test.rule.ts b/packages/@aws-cdk/aws-events/test/test.rule.ts index e448f26f72810..ff69f35779cb0 100644 --- a/packages/@aws-cdk/aws-events/test/test.rule.ts +++ b/packages/@aws-cdk/aws-events/test/test.rule.ts @@ -1,5 +1,4 @@ import { expect } from '@aws-cdk/assert'; -import iam = require('@aws-cdk/aws-iam'); import cdk = require('@aws-cdk/cdk'); import { resolve } from '@aws-cdk/cdk'; import { Test } from 'nodeunit'; @@ -42,7 +41,7 @@ export = { detailType: [ 'detailType1' ], id: [ 'id1', 'id2' ], region: [ 'region1', 'region2', 'region3' ], - resources: [ new cdk.Arn('r1') ], + resources: [ 'r1' ], source: [ 'src1', 'src2' ], time: [ 't1' ], version: [ '0' ] @@ -140,7 +139,7 @@ export = { const t1: IEventRuleTarget = { asEventRuleTarget: () => ({ id: 'T1', - arn: new cdk.Arn('ARN1'), + arn: 'ARN1', kinesisParameters: { partitionKeyPath: 'partitionKeyPath' } }) }; @@ -148,8 +147,8 @@ export = { const t2: IEventRuleTarget = { asEventRuleTarget: () => ({ id: 'T2', - arn: new cdk.Arn('ARN2'), - roleArn: new iam.RoleArn('IAM-ROLE-ARN') + arn: 'ARN2', + roleArn: 'IAM-ROLE-ARN' }) }; @@ -203,13 +202,13 @@ export = { const stack = new cdk.Stack(); const t1: IEventRuleTarget = { asEventRuleTarget: () => ({ - id: 'T1', arn: new cdk.Arn('ARN1'), kinesisParameters: { partitionKeyPath: 'partitionKeyPath' } + id: 'T1', arn: 'ARN1', kinesisParameters: { partitionKeyPath: 'partitionKeyPath' } }) }; - const t2: IEventRuleTarget = { asEventRuleTarget: () => ({ id: 'T2', arn: new cdk.Arn('ARN2'), roleArn: new iam.RoleArn('IAM-ROLE-ARN') }) }; - const t3: IEventRuleTarget = { asEventRuleTarget: () => ({ id: 'T3', arn: new cdk.Arn('ARN3') }) }; - const t4: IEventRuleTarget = { asEventRuleTarget: () => ({ id: 'T4', arn: new cdk.Arn('ARN4') }) }; + const t2: IEventRuleTarget = { asEventRuleTarget: () => ({ id: 'T2', arn: 'ARN2', roleArn: 'IAM-ROLE-ARN' }) }; + const t3: IEventRuleTarget = { asEventRuleTarget: () => ({ id: 'T3', arn: 'ARN3' }) }; + const t4: IEventRuleTarget = { asEventRuleTarget: () => ({ id: 'T4', arn: 'ARN4' }) }; const rule = new EventRule(stack, 'EventRule'); @@ -322,7 +321,7 @@ export = { return { id: 'T1', - arn: new cdk.Arn('ARN1'), + arn: 'ARN1', kinesisParameters: { partitionKeyPath: 'partitionKeyPath' } }; } diff --git a/packages/@aws-cdk/aws-kinesis/lib/stream.ts b/packages/@aws-cdk/aws-kinesis/lib/stream.ts index 19eae41cc3338..03779a16cfd81 100644 --- a/packages/@aws-cdk/aws-kinesis/lib/stream.ts +++ b/packages/@aws-cdk/aws-kinesis/lib/stream.ts @@ -2,7 +2,7 @@ import iam = require('@aws-cdk/aws-iam'); import kms = require('@aws-cdk/aws-kms'); import logs = require('@aws-cdk/aws-logs'); import cdk = require('@aws-cdk/cdk'); -import { cloudformation, StreamArn } from './kinesis.generated'; +import { cloudformation } from './kinesis.generated'; /** * A reference to a stream. The easiest way to instantiate is to call @@ -13,7 +13,7 @@ export interface StreamRefProps { /** * The ARN of the stream. */ - streamArn: StreamArn; + streamArn: string; /** * The KMS key securing the contents of the stream if encryption is enabled. @@ -54,12 +54,12 @@ export abstract class StreamRef extends cdk.Construct implements logs.ILogSubscr /** * The ARN of the stream. */ - public abstract readonly streamArn: StreamArn; + public abstract readonly streamArn: string; /** * The name of the stream */ - public abstract readonly streamName: StreamName; + public abstract readonly streamName: string; /** * Optional KMS encryption key associated with this stream. @@ -76,7 +76,7 @@ export abstract class StreamRef extends cdk.Construct implements logs.ILogSubscr */ public export(): StreamRefProps { return { - streamArn: new StreamArn(new cdk.Output(this, 'StreamArn', { value: this.streamArn }).makeImportValue()), + streamArn: new cdk.Output(this, 'StreamArn', { value: this.streamArn }).makeImportValue().toString(), encryptionKey: this.encryptionKey ? this.encryptionKey.export() : undefined, }; } @@ -279,8 +279,8 @@ export interface StreamProps { * A Kinesis stream. Can be encrypted with a KMS key. */ export class Stream extends StreamRef { - public readonly streamArn: StreamArn; - public readonly streamName: StreamName; + public readonly streamArn: string; + public readonly streamName: string; public readonly encryptionKey?: kms.EncryptionKeyRef; private readonly stream: cloudformation.StreamResource; @@ -303,7 +303,7 @@ export class Stream extends StreamRef { streamEncryption }); this.streamArn = this.stream.streamArn; - this.streamName = this.stream.ref; + this.streamName = this.stream.streamId; this.encryptionKey = encryptionKey; if (props.streamName) { this.addMetadata('aws:cdk:hasPhysicalName', props.streamName); } @@ -362,22 +362,18 @@ export enum StreamEncryption { Kms = 'KMS', } -/** - * The name of the stream. - */ -export class StreamName extends cdk.Token {} - class ImportedStreamRef extends StreamRef { - public readonly streamArn: StreamArn; - public readonly streamName: StreamName; + public readonly streamArn: string; + public readonly streamName: string; public readonly encryptionKey?: kms.EncryptionKeyRef; constructor(parent: cdk.Construct, name: string, props: StreamRefProps) { super(parent, name); this.streamArn = props.streamArn; + // Get the name from the ARN - this.streamName = new StreamName(cdk.Arn.parseToken(props.streamArn).resourceName); + this.streamName = cdk.ArnUtils.parse(props.streamArn).resourceName!; if (props.encryptionKey) { this.encryptionKey = kms.EncryptionKeyRef.import(parent, 'Key', props.encryptionKey); diff --git a/packages/@aws-cdk/aws-kms/test/integ.key.ts b/packages/@aws-cdk/aws-kms/test/integ.key.ts index 17a310d492285..1cc21f3c4354b 100644 --- a/packages/@aws-cdk/aws-kms/test/integ.key.ts +++ b/packages/@aws-cdk/aws-kms/test/integ.key.ts @@ -1,4 +1,4 @@ -import { App, Arn, AwsAccountId, PolicyStatement, Stack } from '@aws-cdk/cdk'; +import { App, AwsAccountId, PolicyStatement, Stack } from '@aws-cdk/cdk'; import { EncryptionKey } from '../lib'; const app = new App(process.argv); diff --git a/packages/@aws-cdk/aws-kms/test/test.key.ts b/packages/@aws-cdk/aws-kms/test/test.key.ts index 492560b2e4c18..640996218fe77 100644 --- a/packages/@aws-cdk/aws-kms/test/test.key.ts +++ b/packages/@aws-cdk/aws-kms/test/test.key.ts @@ -1,5 +1,5 @@ import { exactlyMatchTemplate, expect } from '@aws-cdk/assert'; -import { App, Arn, PolicyDocument, PolicyStatement, Stack } from '@aws-cdk/cdk'; +import { App, PolicyDocument, PolicyStatement, Stack } from '@aws-cdk/cdk'; import { Test } from 'nodeunit'; import { EncryptionKey } from '../lib'; diff --git a/packages/@aws-cdk/aws-lambda/lib/alias.ts b/packages/@aws-cdk/aws-lambda/lib/alias.ts index 6ae1d888bcda2..8bfb5a1c8da5c 100644 --- a/packages/@aws-cdk/aws-lambda/lib/alias.ts +++ b/packages/@aws-cdk/aws-lambda/lib/alias.ts @@ -2,7 +2,7 @@ import iam = require('@aws-cdk/aws-iam'); import cdk = require('@aws-cdk/cdk'); import { FunctionRef } from './lambda-ref'; import { FunctionVersion } from './lambda-version'; -import { cloudformation, FunctionArn, FunctionName } from './lambda.generated'; +import { cloudformation } from './lambda.generated'; import { Permission } from './permission'; /** @@ -58,7 +58,7 @@ export class Alias extends FunctionRef { * Used to be able to use Alias in place of a regular Lambda. Lambda accepts * ARNs everywhere it accepts function names. */ - public readonly functionName: FunctionName; + public readonly functionName: string; /** * ARN of this alias @@ -66,7 +66,7 @@ export class Alias extends FunctionRef { * Used to be able to use Alias in place of a regular Lambda. Lambda accepts * ARNs everywhere it accepts function names. */ - public readonly functionArn: FunctionArn; + public readonly functionArn: string; /** * Role associated with this alias @@ -95,8 +95,8 @@ export class Alias extends FunctionRef { // Not actually the name, but an ARN can be used in all places // where the name is expected, and an ARN can refer to an Alias. - this.functionName = new FunctionName(alias.ref); - this.functionArn = new FunctionArn(alias.ref); + this.functionName = alias.ref; + this.functionArn = alias.aliasArn; } public addPermission(name: string, permission: Permission) { diff --git a/packages/@aws-cdk/aws-lambda/lib/code.ts b/packages/@aws-cdk/aws-lambda/lib/code.ts index 4eb410263c6f7..bb2b22d24a59e 100644 --- a/packages/@aws-cdk/aws-lambda/lib/code.ts +++ b/packages/@aws-cdk/aws-lambda/lib/code.ts @@ -58,7 +58,7 @@ export abstract class Code { * Lambda code from an S3 archive. */ export class S3Code extends Code { - private bucketName: s3.BucketName; + private bucketName: string; constructor(bucket: s3.BucketRef, private key: string, private objectVersion?: string) { super(); diff --git a/packages/@aws-cdk/aws-lambda/lib/lambda-ref.ts b/packages/@aws-cdk/aws-lambda/lib/lambda-ref.ts index 366d034616007..857f9645ece9e 100644 --- a/packages/@aws-cdk/aws-lambda/lib/lambda-ref.ts +++ b/packages/@aws-cdk/aws-lambda/lib/lambda-ref.ts @@ -5,7 +5,7 @@ import iam = require('@aws-cdk/aws-iam'); import logs = require('@aws-cdk/aws-logs'); import s3n = require('@aws-cdk/aws-s3-notifications'); import cdk = require('@aws-cdk/cdk'); -import { cloudformation, FunctionArn, FunctionName } from './lambda.generated'; +import { cloudformation } from './lambda.generated'; import { Permission } from './permission'; /** @@ -17,7 +17,7 @@ export interface FunctionRefProps { * * Format: arn::lambda:::function: */ - functionArn: FunctionArn; + functionArn: string; /** * The IAM execution role associated with this function. @@ -32,7 +32,7 @@ export interface FunctionRefProps { * This needs to be given in order to support allowing connections * to this Lambda. */ - securityGroupId?: ec2.SecurityGroupId; + securityGroupId?: string; } export abstract class FunctionRef extends cdk.Construct @@ -127,12 +127,12 @@ export abstract class FunctionRef extends cdk.Construct /** * The name of the function. */ - public abstract readonly functionName: FunctionName; + public abstract readonly functionName: string; /** * The ARN fo the function. */ - public abstract readonly functionArn: FunctionArn; + public abstract readonly functionArn: string; /** * The IAM role associated with this function. @@ -156,7 +156,7 @@ export abstract class FunctionRef extends cdk.Construct /** * Indicates if the policy that allows CloudWatch logs to publish to this lambda has been added. */ - private logSubscriptionDestinationPolicyAddedFor: logs.LogGroupArn[] = []; + private logSubscriptionDestinationPolicyAddedFor: string[] = []; /** * Adds a permission to the Lambda resource policy. @@ -215,7 +215,7 @@ export abstract class FunctionRef extends cdk.Construct * Returns a RuleTarget that can be used to trigger this Lambda as a * result from a CloudWatch event. */ - public asEventRuleTarget(ruleArn: events.RuleArn, ruleId: string): events.EventRuleTargetProps { + public asEventRuleTarget(ruleArn: string, ruleId: string): events.EventRuleTargetProps { const permissionId = `AllowEventRule${ruleId}`; if (!this.tryFindChild(permissionId)) { this.addPermission(permissionId, { @@ -301,11 +301,10 @@ export abstract class FunctionRef extends cdk.Construct */ public export(): FunctionRefProps { return { - functionArn: new FunctionArn(new cdk.Output(this, 'FunctionArn', { value: this.functionArn }).makeImportValue()), + functionArn: new cdk.Output(this, 'FunctionArn', { value: this.functionArn }).makeImportValue().toString(), securityGroupId: this._connections && this._connections.securityGroup - ? new ec2.SecurityGroupId(new cdk.Output(this, 'SecurityGroupId', { - value: this._connections.securityGroup.securityGroupId - }).makeImportValue()) : undefined + ? new cdk.Output(this, 'SecurityGroupId', { value: this._connections.securityGroup.securityGroupId }).makeImportValue().toString() + : undefined }; } @@ -313,7 +312,7 @@ export abstract class FunctionRef extends cdk.Construct * Allows this Lambda to be used as a destination for bucket notifications. * Use `bucket.onEvent(lambda)` to subscribe. */ - public asBucketNotificationDestination(bucketArn: cdk.Arn, bucketId: string): s3n.BucketNotificationDestinationProps { + public asBucketNotificationDestination(bucketArn: string, bucketId: string): s3n.BucketNotificationDestinationProps { const permissionId = `AllowBucketNotificationsFrom${bucketId}`; if (!this.tryFindChild(permissionId)) { this.addPermission(permissionId, { @@ -355,8 +354,8 @@ export abstract class FunctionRef extends cdk.Construct } class LambdaRefImport extends FunctionRef { - public readonly functionName: FunctionName; - public readonly functionArn: FunctionArn; + public readonly functionName: string; + public readonly functionArn: string; public readonly role?: iam.Role; protected readonly canCreatePermissions = false; @@ -365,7 +364,7 @@ class LambdaRefImport extends FunctionRef { super(parent, name); this.functionArn = props.functionArn; - this.functionName = new FunctionName(this.extractNameFromArn(props.functionArn)); + this.functionName = this.extractNameFromArn(props.functionArn); this.role = props.role; if (props.securityGroupId) { @@ -390,8 +389,8 @@ class LambdaRefImport extends FunctionRef { * * @returns `FnSelect(6, FnSplit(':', arn))` */ - private extractNameFromArn(arn: cdk.Arn) { - return new cdk.FnSelect(6, new cdk.FnSplit(':', arn)); + private extractNameFromArn(arn: string) { + return new cdk.FnSelect(6, new cdk.FnSplit(':', arn)).toString(); } } diff --git a/packages/@aws-cdk/aws-lambda/lib/lambda-version.ts b/packages/@aws-cdk/aws-lambda/lib/lambda-version.ts index fc1f82c0bb1b8..6716995153fb1 100644 --- a/packages/@aws-cdk/aws-lambda/lib/lambda-version.ts +++ b/packages/@aws-cdk/aws-lambda/lib/lambda-version.ts @@ -1,6 +1,6 @@ import { Construct } from '@aws-cdk/cdk'; import { FunctionRef } from './lambda-ref'; -import { cloudformation, Version } from './lambda.generated'; +import { cloudformation } from './lambda.generated'; /** * Properties for a new Lambda version @@ -48,7 +48,7 @@ export class FunctionVersion extends Construct { /** * The most recently deployed version of this function. */ - public readonly functionVersion: Version; + public readonly functionVersion: string; /** * Lambda object this version is associated with diff --git a/packages/@aws-cdk/aws-lambda/lib/lambda.ts b/packages/@aws-cdk/aws-lambda/lib/lambda.ts index 097bf0deae69f..99f52bc1d2083 100644 --- a/packages/@aws-cdk/aws-lambda/lib/lambda.ts +++ b/packages/@aws-cdk/aws-lambda/lib/lambda.ts @@ -5,7 +5,7 @@ import cdk = require('@aws-cdk/cdk'); import { Code } from './code'; import { FunctionRef } from './lambda-ref'; import { FunctionVersion } from './lambda-version'; -import { cloudformation, FunctionArn, FunctionName } from './lambda.generated'; +import { cloudformation } from './lambda.generated'; import { Runtime } from './runtime'; /** @@ -178,12 +178,12 @@ export class Function extends FunctionRef { /** * Name of this function */ - public readonly functionName: FunctionName; + public readonly functionName: string; /** * ARN of this function */ - public readonly functionArn: FunctionArn; + public readonly functionArn: string; /** * Execution role associated with this function @@ -212,7 +212,7 @@ export class Function extends FunctionRef { this.environment = props.environment || { }; - const managedPolicyArns = new Array(); + const managedPolicyArns = new Array(); // the arn is in the form of - arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole managedPolicyArns.push(new iam.AwsManagedPolicy("service-role/AWSLambdaBasicExecutionRole").policyArn); diff --git a/packages/@aws-cdk/aws-lambda/lib/permission.ts b/packages/@aws-cdk/aws-lambda/lib/permission.ts index d4b6215638832..d9f6cd7d4a387 100644 --- a/packages/@aws-cdk/aws-lambda/lib/permission.ts +++ b/packages/@aws-cdk/aws-lambda/lib/permission.ts @@ -1,4 +1,4 @@ -import { Arn, PolicyPrincipal } from '@aws-cdk/cdk'; +import { PolicyPrincipal } from '@aws-cdk/cdk'; /** * Represents a permission statement that can be added to a Lambda's resource policy @@ -52,5 +52,5 @@ export interface Permission { * any bucket from any AWS account that creates a mapping to your function, * can invoke the function. */ - sourceArn?: Arn; + sourceArn?: string; } diff --git a/packages/@aws-cdk/aws-lambda/lib/singleton-lambda.ts b/packages/@aws-cdk/aws-lambda/lib/singleton-lambda.ts index f0c518f33d69f..500fc2675c0fa 100644 --- a/packages/@aws-cdk/aws-lambda/lib/singleton-lambda.ts +++ b/packages/@aws-cdk/aws-lambda/lib/singleton-lambda.ts @@ -2,7 +2,6 @@ import iam = require('@aws-cdk/aws-iam'); import cdk = require('@aws-cdk/cdk'); import { Function, FunctionProps } from './lambda'; import { FunctionRef } from './lambda-ref'; -import { FunctionArn, FunctionName } from './lambda.generated'; import { Permission } from './permission'; /** @@ -36,8 +35,8 @@ export interface SingletonFunctionProps extends FunctionProps { * for every SingletonLambda you create. */ export class SingletonFunction extends FunctionRef { - public readonly functionName: FunctionName; - public readonly functionArn: FunctionArn; + public readonly functionName: string; + public readonly functionArn: string; public readonly role?: iam.Role | undefined; protected readonly canCreatePermissions: boolean; private lambdaFunction: FunctionRef; diff --git a/packages/@aws-cdk/aws-lambda/test/test.lambda.ts b/packages/@aws-cdk/aws-lambda/test/test.lambda.ts index f64f644504059..228a8d3b5586d 100644 --- a/packages/@aws-cdk/aws-lambda/test/test.lambda.ts +++ b/packages/@aws-cdk/aws-lambda/test/test.lambda.ts @@ -119,7 +119,7 @@ export = { action: 'lambda:*', principal: new cdk.ServicePrincipal('s3.amazonaws.com'), sourceAccount: new cdk.AwsAccountId(), - sourceArn: new cdk.Arn('arn:aws:s3:::my_bucket') + sourceArn: 'arn:aws:s3:::my_bucket' }); expect(stack).toMatch({ @@ -187,7 +187,7 @@ export = { const stack = new cdk.Stack(); const fn = newTestLambda(stack); - test.throws(() => fn.addPermission('F1', { principal: new cdk.ArnPrincipal(new cdk.Arn('just:arn')) }), + test.throws(() => fn.addPermission('F1', { principal: new cdk.ArnPrincipal('just:arn') }), /Invalid principal type for Lambda permission statement/); fn.addPermission('S1', { principal: new cdk.ServicePrincipal('my-service') }); diff --git a/packages/@aws-cdk/aws-logs/lib/cross-account-destination.ts b/packages/@aws-cdk/aws-logs/lib/cross-account-destination.ts index cf29d3bc08e64..feb17882286e2 100644 --- a/packages/@aws-cdk/aws-logs/lib/cross-account-destination.ts +++ b/packages/@aws-cdk/aws-logs/lib/cross-account-destination.ts @@ -1,7 +1,7 @@ import iam = require('@aws-cdk/aws-iam'); import cdk = require('@aws-cdk/cdk'); import { LogGroupRef } from './log-group'; -import { cloudformation, DestinationArn, DestinationName } from './logs.generated'; +import { cloudformation } from './logs.generated'; import { ILogSubscriptionDestination, LogSubscriptionDestination } from './subscription-filter'; export interface CrossAccountDestinationProps { @@ -22,7 +22,7 @@ export interface CrossAccountDestinationProps { /** * The log destination target's ARN */ - targetArn: cdk.Arn; + targetArn: string; } /** @@ -44,12 +44,12 @@ export class CrossAccountDestination extends cdk.Construct implements ILogSubscr /** * The name of this CrossAccountDestination object */ - public readonly destinationName: DestinationName; + public readonly destinationName: string; /** * The ARN of this CrossAccountDestination object */ - public readonly destinationArn: DestinationArn; + public readonly destinationArn: string; /** * The inner resource @@ -71,7 +71,7 @@ export class CrossAccountDestination extends cdk.Construct implements ILogSubscr }); this.destinationArn = this.resource.destinationArn; - this.destinationName = this.resource.ref; + this.destinationName = this.resource.destinationName; } public addToPolicy(statement: cdk.PolicyStatement) { diff --git a/packages/@aws-cdk/aws-logs/lib/log-group.ts b/packages/@aws-cdk/aws-logs/lib/log-group.ts index 143989d731dab..f90c245b50a57 100644 --- a/packages/@aws-cdk/aws-logs/lib/log-group.ts +++ b/packages/@aws-cdk/aws-logs/lib/log-group.ts @@ -1,6 +1,6 @@ import cdk = require('@aws-cdk/cdk'); import { LogStream } from './log-stream'; -import { cloudformation, LogGroupArn, LogGroupName } from './logs.generated'; +import { cloudformation } from './logs.generated'; import { MetricFilter } from './metric-filter'; import { FilterPattern, IFilterPattern } from './pattern'; import { ILogSubscriptionDestination, SubscriptionFilter } from './subscription-filter'; @@ -9,7 +9,7 @@ import { ILogSubscriptionDestination, SubscriptionFilter } from './subscription- * Properties for importing a LogGroup */ export interface LogGroupRefProps { - logGroupArn: LogGroupArn; + logGroupArn: string; } /** @@ -26,12 +26,12 @@ export abstract class LogGroupRef extends cdk.Construct { /** * The ARN of this log group */ - public abstract readonly logGroupArn: LogGroupArn; + public abstract readonly logGroupArn: string; /** * The name of this log group */ - public abstract readonly logGroupName: LogGroupName; + public abstract readonly logGroupName: string; /** * Create a new Log Stream for this Log Group @@ -80,7 +80,7 @@ export abstract class LogGroupRef extends cdk.Construct { */ public export(): LogGroupRefProps { return { - logGroupArn: new LogGroupArn(new cdk.Output(this, 'LogGroupArn', { value: this.logGroupArn }).makeImportValue()) + logGroupArn: new cdk.Output(this, 'LogGroupArn', { value: this.logGroupArn }).makeImportValue().toString() }; } @@ -148,12 +148,12 @@ export class LogGroup extends LogGroupRef { /** * The ARN of this log group */ - public readonly logGroupArn: LogGroupArn; + public readonly logGroupArn: string; /** * The name of this log group */ - public readonly logGroupName: LogGroupName; + public readonly logGroupName: string; constructor(parent: cdk.Construct, id: string, props: LogGroupProps = {}) { super(parent, id); @@ -176,7 +176,7 @@ export class LogGroup extends LogGroupRef { } this.logGroupArn = resource.logGroupArn; - this.logGroupName = resource.ref; + this.logGroupName = resource.logGroupName; } } @@ -187,18 +187,18 @@ class ImportedLogGroup extends LogGroupRef { /** * The ARN of this log group */ - public readonly logGroupArn: LogGroupArn; + public readonly logGroupArn: string; /** * The name of this log group */ - public readonly logGroupName: LogGroupName; + public readonly logGroupName: string; constructor(parent: cdk.Construct, id: string, props: LogGroupRefProps) { super(parent, id); this.logGroupArn = props.logGroupArn; - this.logGroupName = new LogGroupName(props.logGroupArn.resourceNameComponent(':')); + this.logGroupName = cdk.ArnUtils.resourceNameComponent(props.logGroupArn, ':'); } } diff --git a/packages/@aws-cdk/aws-logs/lib/log-stream.ts b/packages/@aws-cdk/aws-logs/lib/log-stream.ts index 583f0bf92eacb..470de2afdd869 100644 --- a/packages/@aws-cdk/aws-logs/lib/log-stream.ts +++ b/packages/@aws-cdk/aws-logs/lib/log-stream.ts @@ -1,12 +1,12 @@ import cdk = require('@aws-cdk/cdk'); import { LogGroupRef } from './log-group'; -import { cloudformation, LogStreamName } from './logs.generated'; +import { cloudformation } from './logs.generated'; /** * Properties for importing a LogStream */ export interface LogStreamRefProps { - logStreamName: LogStreamName; + logStreamName: string; } /** @@ -23,14 +23,14 @@ export abstract class LogStreamRef extends cdk.Construct { /** * The name of this log stream */ - public abstract readonly logStreamName: LogStreamName; + public abstract readonly logStreamName: string; /** * Export this LogStream */ public export(): LogStreamRefProps { return { - logStreamName: new LogStreamName(new cdk.Output(this, 'LogStreamName', { value: this.logStreamName }).makeImportValue()) + logStreamName: new cdk.Output(this, 'LogStreamName', { value: this.logStreamName }).makeImportValue().toString() }; } } @@ -74,7 +74,7 @@ export class LogStream extends LogStreamRef { /** * The name of this log stream */ - public readonly logStreamName: LogStreamName; + public readonly logStreamName: string; constructor(parent: cdk.Construct, id: string, props: LogStreamProps) { super(parent, id); @@ -88,7 +88,7 @@ export class LogStream extends LogStreamRef { resource.options.deletionPolicy = cdk.DeletionPolicy.Retain; } - this.logStreamName = resource.ref; + this.logStreamName = resource.logStreamName; } } @@ -99,7 +99,7 @@ class ImportedLogStream extends LogStreamRef { /** * The name of this log stream */ - public readonly logStreamName: LogStreamName; + public readonly logStreamName: string; constructor(parent: cdk.Construct, id: string, props: LogStreamRefProps) { super(parent, id); diff --git a/packages/@aws-cdk/aws-logs/lib/subscription-filter.ts b/packages/@aws-cdk/aws-logs/lib/subscription-filter.ts index 949b6984ee3b5..292af664e99ef 100644 --- a/packages/@aws-cdk/aws-logs/lib/subscription-filter.ts +++ b/packages/@aws-cdk/aws-logs/lib/subscription-filter.ts @@ -28,7 +28,7 @@ export interface LogSubscriptionDestination { /** * The ARN of the subscription's destination */ - readonly arn: cdk.Arn; + readonly arn: string; /** * The role to assume to write log events to the destination diff --git a/packages/@aws-cdk/aws-logs/test/test.destination.ts b/packages/@aws-cdk/aws-logs/test/test.destination.ts index 63b33a0e62815..30b038a8d6205 100644 --- a/packages/@aws-cdk/aws-logs/test/test.destination.ts +++ b/packages/@aws-cdk/aws-logs/test/test.destination.ts @@ -16,7 +16,7 @@ export = { new CrossAccountDestination(stack, 'Dest', { destinationName: 'MyDestination', role, - targetArn: new cdk.Arn('arn:bogus') + targetArn: 'arn:bogus' }); // THEN @@ -39,7 +39,7 @@ export = { const dest = new CrossAccountDestination(stack, 'Dest', { destinationName: 'MyDestination', role, - targetArn: new cdk.Arn('arn:bogus') + targetArn: 'arn:bogus' }); // WHEN diff --git a/packages/@aws-cdk/aws-logs/test/test.subscriptionfilter.ts b/packages/@aws-cdk/aws-logs/test/test.subscriptionfilter.ts index e54c6acd52a44..4603a1a6ae8ee 100644 --- a/packages/@aws-cdk/aws-logs/test/test.subscriptionfilter.ts +++ b/packages/@aws-cdk/aws-logs/test/test.subscriptionfilter.ts @@ -1,5 +1,5 @@ import { expect, haveResource } from '@aws-cdk/assert'; -import { Arn, Stack } from '@aws-cdk/cdk'; +import { Stack } from '@aws-cdk/cdk'; import { Test } from 'nodeunit'; import { FilterPattern, ILogSubscriptionDestination, LogGroup, LogGroupRef, SubscriptionFilter } from '../lib'; diff --git a/packages/@aws-cdk/aws-neptune/lib/index.ts b/packages/@aws-cdk/aws-neptune/lib/index.ts index 22cf821079fa3..0a081f5bb993b 100644 --- a/packages/@aws-cdk/aws-neptune/lib/index.ts +++ b/packages/@aws-cdk/aws-neptune/lib/index.ts @@ -1,5 +1,4 @@ import ec2 = require('@aws-cdk/aws-ec2'); -import kms = require('@aws-cdk/aws-kms'); import rds = require('@aws-cdk/aws-rds'); import cdk = require('@aws-cdk/cdk'); @@ -61,7 +60,7 @@ export interface NeptuneDatabaseProps { /** * ARN of KMS key if you want to enable storage encryption */ - kmsKeyArn?: kms.KeyArn; + kmsKeyArn?: string; /** * A daily time range in 24-hours UTC format in which backups preferably execute. @@ -86,12 +85,12 @@ export class NeptuneDatabase extends cdk.Construct implements ec2.IConnectable { /** * Identifier of the cluster */ - public readonly clusterIdentifier: rds.DBClusterName; + public readonly clusterIdentifier: string; /** * Identifiers of the replicas */ - public readonly instanceIdentifiers: rds.DBInstanceId[] = []; + public readonly instanceIdentifiers: string[] = []; /** * The endpoint to use for read/write operations diff --git a/packages/@aws-cdk/aws-neptune/test/test.neptune.ts b/packages/@aws-cdk/aws-neptune/test/test.neptune.ts index f05345abf39db..1d8ee3e084458 100644 --- a/packages/@aws-cdk/aws-neptune/test/test.neptune.ts +++ b/packages/@aws-cdk/aws-neptune/test/test.neptune.ts @@ -1,5 +1,4 @@ import ec2 = require('@aws-cdk/aws-ec2'); -import rds = require('@aws-cdk/aws-rds'); import cdk = require('@aws-cdk/cdk'); import { Test } from 'nodeunit'; import { NeptuneDatabase } from '../lib'; @@ -12,8 +11,8 @@ exports = { new NeptuneDatabase(stack, 'Database', { masterUser: { - username: new rds.Username('admin'), - password: new rds.Password('tooshort'), + username: 'admin', + password: 'tooshort', }, instanceProps: { instanceType: new ec2.InstanceTypePair(ec2.InstanceClass.Burstable2, ec2.InstanceSize.Small), diff --git a/packages/@aws-cdk/aws-quickstarts/lib/rdgw.ts b/packages/@aws-cdk/aws-quickstarts/lib/rdgw.ts index 55770bdecd224..d7bca3737dbe1 100644 --- a/packages/@aws-cdk/aws-quickstarts/lib/rdgw.ts +++ b/packages/@aws-cdk/aws-quickstarts/lib/rdgw.ts @@ -48,7 +48,7 @@ export class RemoteDesktopGateway extends cdk.Construct implements ec2.IConnecta }); const securityGroup = ec2.SecurityGroupRef.import(this, 'SecurityGroup', { - securityGroupId: new ec2.SecurityGroupId(nestedStack.getAtt('Outputs.RemoteDesktopGatewaySGID')) + securityGroupId: nestedStack.getAtt('Outputs.RemoteDesktopGatewaySGID') }); const defaultPortRange = new ec2.TcpPort(RemoteDesktopGateway.PORT); diff --git a/packages/@aws-cdk/aws-rds/lib/cluster-ref.ts b/packages/@aws-cdk/aws-rds/lib/cluster-ref.ts index 6711cc455d873..63c609c3e7ecf 100644 --- a/packages/@aws-cdk/aws-rds/lib/cluster-ref.ts +++ b/packages/@aws-cdk/aws-rds/lib/cluster-ref.ts @@ -1,6 +1,5 @@ import ec2 = require('@aws-cdk/aws-ec2'); import cdk = require('@aws-cdk/cdk'); -import { DBClusterEndpointAddress, DBClusterEndpointPort, DBClusterName, DBInstanceId } from './rds.generated'; /** * Create a clustered database with a given number of instances. @@ -21,12 +20,12 @@ export abstract class DatabaseClusterRef extends cdk.Construct implements ec2.IC /** * Identifier of the cluster */ - public abstract readonly clusterIdentifier: DBClusterName; + public abstract readonly clusterIdentifier: string; /** * Identifiers of the replicas */ - public abstract readonly instanceIdentifiers: DBInstanceId[] = []; + public abstract readonly instanceIdentifiers: string[] = []; /** * The endpoint to use for read/write operations @@ -46,7 +45,7 @@ export abstract class DatabaseClusterRef extends cdk.Construct implements ec2.IC /** * The security group for this database cluster */ - protected abstract readonly securityGroupId: ec2.SecurityGroupId; + protected abstract readonly securityGroupId: string; /** * Export a Database Cluster for importing in another stack @@ -54,13 +53,13 @@ export abstract class DatabaseClusterRef extends cdk.Construct implements ec2.IC public export(): DatabaseClusterRefProps { // tslint:disable:max-line-length return { - port: new DBClusterEndpointPort(new cdk.Output(this, 'Port', { value: this.clusterEndpoint.port, }).makeImportValue()), - securityGroupId: new ec2.SecurityGroupId(new cdk.Output(this, 'SecurityGroupId', { value: this.securityGroupId, }).makeImportValue()), - clusterIdentifier: new DBClusterName(new cdk.Output(this, 'ClusterIdentifier', { value: this.clusterIdentifier, }).makeImportValue()), - instanceIdentifiers: new cdk.StringListOutput(this, 'InstanceIdentifiers', { values: this.instanceIdentifiers }).makeImportValues().map(x => new DBInstanceId(x)), - clusterEndpointAddress: new DBClusterEndpointAddress(new cdk.Output(this, 'ClusterEndpointAddress', { value: this.clusterEndpoint.hostname, }).makeImportValue()), - readerEndpointAddress: new DBClusterEndpointAddress(new cdk.Output(this, 'ReaderEndpointAddress', { value: this.readerEndpoint.hostname, }).makeImportValue()), - instanceEndpointAddresses: new cdk.StringListOutput(this, 'InstanceEndpointAddresses', { values: this.instanceEndpoints.map(e => e.hostname) }).makeImportValues().map(x => new DBClusterEndpointAddress(x)), + port: new cdk.Output(this, 'Port', { value: this.clusterEndpoint.port, }).makeImportValue().toString(), + securityGroupId: new cdk.Output(this, 'SecurityGroupId', { value: this.securityGroupId, }).makeImportValue().toString(), + clusterIdentifier: new cdk.Output(this, 'ClusterIdentifier', { value: this.clusterIdentifier, }).makeImportValue().toString(), + instanceIdentifiers: new cdk.StringListOutput(this, 'InstanceIdentifiers', { values: this.instanceIdentifiers }).makeImportValues().map(x => x.toString()), + clusterEndpointAddress: new cdk.Output(this, 'ClusterEndpointAddress', { value: this.clusterEndpoint.hostname, }).makeImportValue().toString(), + readerEndpointAddress: new cdk.Output(this, 'ReaderEndpointAddress', { value: this.readerEndpoint.hostname, }).makeImportValue().toString(), + instanceEndpointAddresses: new cdk.StringListOutput(this, 'InstanceEndpointAddresses', { values: this.instanceEndpoints.map(e => e.hostname) }).makeImportValues().map(x => x.toString()), }; // tslint:enable:max-line-length } @@ -73,38 +72,38 @@ export interface DatabaseClusterRefProps { /** * The database port */ - port: DBClusterEndpointPort; + port: string; /** * The security group for this database cluster */ - securityGroupId: ec2.SecurityGroupId; + securityGroupId: string; /** * Identifier for the cluster */ - clusterIdentifier: DBClusterName; + clusterIdentifier: string; /** * Identifier for the instances */ - instanceIdentifiers: DBInstanceId[]; + instanceIdentifiers: string[]; // Actual underlying type: DBInstanceId[], but we have to type it more loosely for Java's benefit. /** * Cluster endpoint address */ - clusterEndpointAddress: DBClusterEndpointAddress; + clusterEndpointAddress: string; /** * Reader endpoint address */ - readerEndpointAddress: DBClusterEndpointAddress; + readerEndpointAddress: string; /** * Endpoint addresses of individual instances */ - instanceEndpointAddresses: DBClusterEndpointAddress[]; + instanceEndpointAddresses: string[]; } /** @@ -124,12 +123,12 @@ class ImportedDatabaseCluster extends DatabaseClusterRef { /** * Identifier of the cluster */ - public readonly clusterIdentifier: DBClusterName; + public readonly clusterIdentifier: string; /** * Identifiers of the replicas */ - public readonly instanceIdentifiers: DBInstanceId[] = []; + public readonly instanceIdentifiers: string[] = []; /** * The endpoint to use for read/write operations @@ -149,7 +148,7 @@ class ImportedDatabaseCluster extends DatabaseClusterRef { /** * Security group identifier of this database */ - protected readonly securityGroupId: ec2.SecurityGroupId; + protected readonly securityGroupId: string; constructor(parent: cdk.Construct, name: string, props: DatabaseClusterRefProps) { super(parent, name); @@ -167,11 +166,6 @@ class ImportedDatabaseCluster extends DatabaseClusterRef { } } -/** - * A complete socket address (hostname + ":" + port) - */ -export class SocketAddress extends cdk.Token { } - /** * Connection endpoint of a database cluster or instance * @@ -181,21 +175,21 @@ export class Endpoint { /** * The hostname of the endpoint */ - public readonly hostname: DBClusterEndpointAddress; + public readonly hostname: string; /** * The port of the endpoint */ - public readonly port: DBClusterEndpointPort; + public readonly port: string; /** * The combination of "HOSTNAME:PORT" for this endpoint */ - public readonly socketAddress: SocketAddress; + public readonly socketAddress: string; - constructor(address: DBClusterEndpointAddress, port: DBClusterEndpointPort) { + constructor(address: string, port: string) { this.hostname = address; this.port = port; - this.socketAddress = new SocketAddress(new cdk.FnJoin(":", [address, port])); + this.socketAddress = `${address}:${port}`; } } diff --git a/packages/@aws-cdk/aws-rds/lib/cluster.ts b/packages/@aws-cdk/aws-rds/lib/cluster.ts index 8dbd844ca1432..738e4ea9441ba 100644 --- a/packages/@aws-cdk/aws-rds/lib/cluster.ts +++ b/packages/@aws-cdk/aws-rds/lib/cluster.ts @@ -1,9 +1,8 @@ import ec2 = require('@aws-cdk/aws-ec2'); -import kms = require('@aws-cdk/aws-kms'); import cdk = require('@aws-cdk/cdk'); import { DatabaseClusterRef, Endpoint } from './cluster-ref'; import { BackupProps, DatabaseClusterEngine, InstanceProps, Login, Parameters } from './props'; -import { cloudformation, DBClusterEndpointAddress, DBClusterEndpointPort, DBClusterName, DBInstanceId } from './rds.generated'; +import { cloudformation } from './rds.generated'; /** * Properties for a new database cluster @@ -71,7 +70,7 @@ export interface DatabaseClusterProps { /** * ARN of KMS key if you want to enable storage encryption */ - kmsKeyArn?: kms.KeyArn; + kmsKeyArn?: string; /** * A daily time range in 24-hours UTC format in which backups preferably execute. @@ -95,12 +94,12 @@ export class DatabaseCluster extends DatabaseClusterRef { /** * Identifier of the cluster */ - public readonly clusterIdentifier: DBClusterName; + public readonly clusterIdentifier: string; /** * Identifiers of the replicas */ - public readonly instanceIdentifiers: DBInstanceId[] = []; + public readonly instanceIdentifiers: string[] = []; /** * The endpoint to use for read/write operations @@ -125,7 +124,7 @@ export class DatabaseCluster extends DatabaseClusterRef { /** * Security group identifier of this database */ - protected readonly securityGroupId: ec2.SecurityGroupId; + protected readonly securityGroupId: string; constructor(parent: cdk.Construct, name: string, props: DatabaseClusterProps) { super(parent, name); @@ -169,7 +168,7 @@ export class DatabaseCluster extends DatabaseClusterRef { this.clusterIdentifier = cluster.ref; this.clusterEndpoint = new Endpoint(cluster.dbClusterEndpointAddress, cluster.dbClusterEndpointPort); - this.readerEndpoint = new Endpoint(new DBClusterEndpointAddress(cluster.dbClusterReadEndpointAddress), cluster.dbClusterEndpointPort); + this.readerEndpoint = new Endpoint(cluster.dbClusterReadEndpointAddress, cluster.dbClusterEndpointPort); const instanceCount = props.instances != null ? props.instances : 2; if (instanceCount < 1) { @@ -206,9 +205,7 @@ export class DatabaseCluster extends DatabaseClusterRef { } this.instanceIdentifiers.push(instance.ref); - this.instanceEndpoints.push(new Endpoint( - new DBClusterEndpointAddress(instance.dbInstanceEndpointAddress), - new DBClusterEndpointPort(instance.dbInstanceEndpointPort))); + this.instanceEndpoints.push(new Endpoint(instance.dbInstanceEndpointAddress, instance.dbInstanceEndpointPort)); } const defaultPortRange = new ec2.TcpPortFromAttribute(this.clusterEndpoint.port); diff --git a/packages/@aws-cdk/aws-rds/lib/props.ts b/packages/@aws-cdk/aws-rds/lib/props.ts index 3f1b52ddc12a1..436d2771e4724 100644 --- a/packages/@aws-cdk/aws-rds/lib/props.ts +++ b/packages/@aws-cdk/aws-rds/lib/props.ts @@ -1,5 +1,4 @@ import ec2 = require('@aws-cdk/aws-ec2'); -import cdk = require('@aws-cdk/cdk'); /** * The engine for the database cluster @@ -60,7 +59,7 @@ export interface Login { /** * Username */ - username: Username; + username: string; /** * Password @@ -68,19 +67,9 @@ export interface Login { * Do not put passwords in your CDK code directly. Import it from a Stack * Parameter or the SSM Parameter Store instead. */ - password: Password; + password: string; } -/** - * An RDS username - */ -export class Username extends cdk.Token {} - -/** - * An RDS password - */ -export class Password extends cdk.Token {} - /** * Type for database parameters */ diff --git a/packages/@aws-cdk/aws-rds/test/integ.cluster.ts b/packages/@aws-cdk/aws-rds/test/integ.cluster.ts index 2458f833319fb..2790837920754 100644 --- a/packages/@aws-cdk/aws-rds/test/integ.cluster.ts +++ b/packages/@aws-cdk/aws-rds/test/integ.cluster.ts @@ -1,6 +1,6 @@ import ec2 = require('@aws-cdk/aws-ec2'); import cdk = require('@aws-cdk/cdk'); -import { DatabaseCluster, DatabaseClusterEngine, Password, Username } from '../lib'; +import { DatabaseCluster, DatabaseClusterEngine } from '../lib'; const app = new cdk.App(process.argv); const stack = new cdk.Stack(app, 'aws-cdk-rds-integ'); @@ -10,8 +10,8 @@ const vpc = new ec2.VpcNetwork(stack, 'VPC', { maxAZs: 2 }); const cluster = new DatabaseCluster(stack, 'Database', { engine: DatabaseClusterEngine.Aurora, masterUser: { - username: new Username('admin'), - password: new Password('7959866cacc02c2d243ecfe177464fe6'), + username: 'admin', + password: '7959866cacc02c2d243ecfe177464fe6', }, instanceProps: { instanceType: new ec2.InstanceTypePair(ec2.InstanceClass.Burstable2, ec2.InstanceSize.Small), diff --git a/packages/@aws-cdk/aws-rds/test/test.cluster.ts b/packages/@aws-cdk/aws-rds/test/test.cluster.ts index c753d8a848606..448ddd3c685ec 100644 --- a/packages/@aws-cdk/aws-rds/test/test.cluster.ts +++ b/packages/@aws-cdk/aws-rds/test/test.cluster.ts @@ -2,7 +2,7 @@ import { expect, haveResource } from '@aws-cdk/assert'; import ec2 = require('@aws-cdk/aws-ec2'); import cdk = require('@aws-cdk/cdk'); import { Test } from 'nodeunit'; -import { DatabaseCluster, DatabaseClusterEngine, DatabaseClusterRef, Password, Username } from '../lib'; +import { DatabaseCluster, DatabaseClusterEngine, DatabaseClusterRef } from '../lib'; export = { 'check that instantiation works'(test: Test) { @@ -14,8 +14,8 @@ export = { new DatabaseCluster(stack, 'Database', { engine: DatabaseClusterEngine.Aurora, masterUser: { - username: new Username('admin'), - password: new Password('tooshort'), + username: 'admin', + password: 'tooshort', }, instanceProps: { instanceType: new ec2.InstanceTypePair(ec2.InstanceClass.Burstable2, ec2.InstanceSize.Small), @@ -42,8 +42,8 @@ export = { const cluster = new DatabaseCluster(stack1, 'Database', { engine: DatabaseClusterEngine.Aurora, masterUser: { - username: new Username('admin'), - password: new Password('tooshort'), + username: 'admin', + password: 'tooshort', }, instanceProps: { instanceType: new ec2.InstanceTypePair(ec2.InstanceClass.Burstable2, ec2.InstanceSize.Small), @@ -68,8 +68,8 @@ export = { engine: DatabaseClusterEngine.Aurora, instances: 1, masterUser: { - username: new Username('admin'), - password: new Password('tooshort'), + username: 'admin', + password: 'tooshort', }, instanceProps: { instanceType: new ec2.InstanceTypePair(ec2.InstanceClass.Burstable2, ec2.InstanceSize.Small), diff --git a/packages/@aws-cdk/aws-route53/lib/hosted-zone-ref.ts b/packages/@aws-cdk/aws-route53/lib/hosted-zone-ref.ts index c1f216506eda7..c11450f91bdd2 100644 --- a/packages/@aws-cdk/aws-route53/lib/hosted-zone-ref.ts +++ b/packages/@aws-cdk/aws-route53/lib/hosted-zone-ref.ts @@ -1,5 +1,4 @@ import { Construct, Output } from "@aws-cdk/cdk"; -import { HostedZoneId } from './route53.generated'; /** * Imported or created hosted zone @@ -12,7 +11,7 @@ export abstract class HostedZoneRef extends Construct { /** * ID of this hosted zone */ - public abstract readonly hostedZoneId: HostedZoneId; + public abstract readonly hostedZoneId: string; /** * FQDN of this hosted zone @@ -24,7 +23,7 @@ export abstract class HostedZoneRef extends Construct { */ public export(): HostedZoneRefProps { return { - hostedZoneId: new HostedZoneId(new Output(this, 'HostedZoneId', { value: this.hostedZoneId }).makeImportValue()), + hostedZoneId: new Output(this, 'HostedZoneId', { value: this.hostedZoneId }).makeImportValue().toString(), zoneName: this.zoneName, }; } @@ -37,7 +36,7 @@ export interface HostedZoneRefProps { /** * Identifier of the hosted zone */ - hostedZoneId: HostedZoneId; + hostedZoneId: string; /** * Name of the hosted zone @@ -49,7 +48,7 @@ export interface HostedZoneRefProps { * Imported hosted zone */ export class ImportedHostedZone extends HostedZoneRef { - public readonly hostedZoneId: HostedZoneId; + public readonly hostedZoneId: string; public readonly zoneName: string; diff --git a/packages/@aws-cdk/aws-route53/lib/hosted-zone.ts b/packages/@aws-cdk/aws-route53/lib/hosted-zone.ts index 093f6a9a92c99..f6e8f557e09d9 100644 --- a/packages/@aws-cdk/aws-route53/lib/hosted-zone.ts +++ b/packages/@aws-cdk/aws-route53/lib/hosted-zone.ts @@ -1,8 +1,7 @@ import ec2 = require('@aws-cdk/aws-ec2'); -import logs = require('@aws-cdk/aws-logs'); import cdk = require('@aws-cdk/cdk'); import { HostedZoneRef } from './hosted-zone-ref'; -import { cloudformation, HostedZoneId, HostedZoneNameServers } from './route53.generated'; +import { cloudformation, HostedZoneNameServers } from './route53.generated'; import { validateZoneName } from './util'; /** @@ -26,7 +25,7 @@ export interface PublicHostedZoneProps { * * @default no DNS query logging */ - queryLogsLogGroupArn?: logs.LogGroupArn; + queryLogsLogGroupArn?: string; } /** @@ -36,7 +35,7 @@ export class PublicHostedZone extends HostedZoneRef { /** * Identifier of this hosted zone */ - public readonly hostedZoneId: HostedZoneId; + public readonly hostedZoneId: string; /** * Fully qualified domain name for the hosted zone @@ -83,7 +82,7 @@ export class PrivateHostedZone extends HostedZoneRef { /** * Identifier of this hosted zone */ - public readonly hostedZoneId: HostedZoneId; + public readonly hostedZoneId: string; /** * Fully qualified domain name for the hosted zone diff --git a/packages/@aws-cdk/aws-s3/lib/bucket.ts b/packages/@aws-cdk/aws-s3/lib/bucket.ts index 539961830fe06..a272bfcaa3a90 100644 --- a/packages/@aws-cdk/aws-s3/lib/bucket.ts +++ b/packages/@aws-cdk/aws-s3/lib/bucket.ts @@ -152,7 +152,7 @@ export abstract class BucketRef extends cdk.Construct { * bucket is returned. * @returns an ObjectS3Url token */ - public urlForObject(key?: any): S3Url { + public urlForObject(key?: any): string { const components = [ 'https://', 's3.', new cdk.AwsRegion(), '.', new cdk.AwsURLSuffix(), '/', this.bucketName ]; if (key) { // trim prepending '/' @@ -163,7 +163,7 @@ export abstract class BucketRef extends cdk.Construct { components.push(key); } - return new S3Url(new cdk.FnConcat(...components)); + return new cdk.FnConcat(...components).toString(); } /** @@ -587,20 +587,6 @@ export enum BucketEncryption { Kms = 'KMS', } -/** - * A key to an S3 object. - */ -export class ObjectKey extends cdk.Token { - -} - -/** - * The web URL (https://s3.us-west-1.amazonaws.com/bucket/key) of an S3 object. - */ -export class S3Url extends cdk.Token { - -} - /** * Notification event types. */ diff --git a/packages/@aws-cdk/aws-s3/lib/notifications-resource/notifications-resource-handler.ts b/packages/@aws-cdk/aws-s3/lib/notifications-resource/notifications-resource-handler.ts index 37ad42e21f308..e42b6d06d16a4 100644 --- a/packages/@aws-cdk/aws-s3/lib/notifications-resource/notifications-resource-handler.ts +++ b/packages/@aws-cdk/aws-s3/lib/notifications-resource/notifications-resource-handler.ts @@ -42,7 +42,7 @@ export class NotificationsResourceHandler extends cdk.Construct { * The ARN of the handler's lambda function. Used as a service token in the * custom resource. */ - public readonly functionArn: cdk.Arn; + public readonly functionArn: string; constructor(parent: cdk.Construct, id: string) { super(parent, id); @@ -50,7 +50,7 @@ export class NotificationsResourceHandler extends cdk.Construct { const role = new iam.Role(this, 'Role', { assumedBy: new cdk.ServicePrincipal('lambda.amazonaws.com'), managedPolicyArns: [ - cdk.Arn.fromComponents({ + cdk.ArnUtils.fromComponents({ service: 'iam', region: '', // no region for managed policy account: 'aws', // the account for a managed policy is 'aws' @@ -77,7 +77,7 @@ export class NotificationsResourceHandler extends cdk.Construct { } }); - this.functionArn = new cdk.Arn(resource.getAtt('Arn')); + this.functionArn = resource.getAtt('Arn'); } } diff --git a/packages/@aws-cdk/aws-s3/lib/util.ts b/packages/@aws-cdk/aws-s3/lib/util.ts index 0979517900eb1..453ac125f6194 100644 --- a/packages/@aws-cdk/aws-s3/lib/util.ts +++ b/packages/@aws-cdk/aws-s3/lib/util.ts @@ -9,7 +9,7 @@ export function parseBucketArn(props: BucketRefProps): string { } if (props.bucketName) { - return cdk.ArnUtils.format({ + return cdk.ArnUtils.fromComponents({ // S3 Bucket names are globally unique in a partition, // and so their ARNs have empty region and account components region: '', diff --git a/packages/@aws-cdk/aws-s3/test/test.notifications.ts b/packages/@aws-cdk/aws-s3/test/test.notifications.ts index f229f9d307bcd..a0b80a063d464 100644 --- a/packages/@aws-cdk/aws-s3/test/test.notifications.ts +++ b/packages/@aws-cdk/aws-s3/test/test.notifications.ts @@ -98,21 +98,21 @@ export = { const queueTarget: s3n.IBucketNotificationDestination = { asBucketNotificationDestination: _ => ({ type: s3n.BucketNotificationDestinationType.Queue, - arn: new cdk.Arn('arn:aws:sqs:...') + arn: 'arn:aws:sqs:...' }) }; const lambdaTarget: s3n.IBucketNotificationDestination = { asBucketNotificationDestination: _ => ({ type: s3n.BucketNotificationDestinationType.Lambda, - arn: new cdk.Arn('arn:aws:lambda:...') + arn: 'arn:aws:lambda:...' }) }; const topicTarget: s3n.IBucketNotificationDestination = { asBucketNotificationDestination: _ => ({ type: s3n.BucketNotificationDestinationType.Topic, - arn: new cdk.Arn('arn:aws:sns:...') + arn: 'arn:aws:sns:...' }) }; @@ -179,14 +179,14 @@ export = { bucket.onEvent(s3.EventType.ObjectRemovedDelete, { asBucketNotificationDestination: _ => ({ type: s3n.BucketNotificationDestinationType.Queue, - arn: new cdk.Arn('arn:aws:sqs:...:queue1') + arn: 'arn:aws:sqs:...:queue1' }) }); bucket.onEvent(s3.EventType.ObjectRemovedDelete, { asBucketNotificationDestination: _ => ({ type: s3n.BucketNotificationDestinationType.Queue, - arn: new cdk.Arn('arn:aws:sqs:...:queue2') + arn: 'arn:aws:sqs:...:queue2' }) }); @@ -228,7 +228,7 @@ export = { const bucketNotificationTarget = { type: s3n.BucketNotificationDestinationType.Queue, - arn: new cdk.Arn('arn:aws:sqs:...') + arn: 'arn:aws:sqs:...' }; bucket.onEvent(s3.EventType.ObjectRemovedDelete, { asBucketNotificationDestination: _ => bucketNotificationTarget }, { prefix: 'images/', suffix: '.jpg' }); @@ -279,7 +279,7 @@ export = { const dependent = new cdk.Resource(stack, 'Dependent', { type: 'DependOnMe' }); const dest: s3n.IBucketNotificationDestination = { asBucketNotificationDestination: () => ({ - arn: new cdk.Arn('arn'), + arn: 'arn', type: s3n.BucketNotificationDestinationType.Queue, dependencies: [ dependent ] }) diff --git a/packages/@aws-cdk/aws-sns/lib/topic-ref.ts b/packages/@aws-cdk/aws-sns/lib/topic-ref.ts index f4e43206b82eb..705c1321b1ff6 100644 --- a/packages/@aws-cdk/aws-sns/lib/topic-ref.ts +++ b/packages/@aws-cdk/aws-sns/lib/topic-ref.ts @@ -6,7 +6,6 @@ import s3n = require('@aws-cdk/aws-s3-notifications'); import sqs = require('@aws-cdk/aws-sqs'); import cdk = require('@aws-cdk/cdk'); import { TopicPolicy } from './policy'; -import { TopicArn, TopicName } from './sns.generated'; import { Subscription, SubscriptionProtocol } from './subscription'; /** @@ -20,9 +19,9 @@ export abstract class TopicRef extends cdk.Construct implements events.IEventRul return new ImportedTopic(parent, name, props); } - public abstract readonly topicArn: TopicArn; + public abstract readonly topicArn: string; - public abstract readonly topicName: TopicName; + public abstract readonly topicName: string; /** * Controls automatic creation of policy objects. @@ -47,8 +46,8 @@ export abstract class TopicRef extends cdk.Construct implements events.IEventRul */ public export(): TopicRefProps { return { - topicArn: new TopicArn(new cdk.Output(this, 'TopicArn', { value: this.topicArn }).makeImportValue()), - topicName: new TopicName(new cdk.Output(this, 'TopicName', { value: this.topicName }).makeImportValue()), + topicArn: new cdk.Output(this, 'TopicArn', { value: this.topicArn }).makeImportValue().toString(), + topicName: new cdk.Output(this, 'TopicName', { value: this.topicName }).makeImportValue().toString(), }; } @@ -207,7 +206,7 @@ export abstract class TopicRef extends cdk.Construct implements events.IEventRul * * @see https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/resource-based-policies-cwe.html#sns-permissions */ - public asEventRuleTarget(_ruleArn: events.RuleArn, _ruleId: string): events.EventRuleTargetProps { + public asEventRuleTarget(_ruleArn: string, _ruleId: string): events.EventRuleTargetProps { if (!this.eventRuleTargetPolicyAdded) { this.addToResourcePolicy(new cdk.PolicyStatement() .addAction('sns:Publish') @@ -223,7 +222,7 @@ export abstract class TopicRef extends cdk.Construct implements events.IEventRul }; } - public get alarmActionArn(): cdk.Arn { + public get alarmActionArn(): string { return this.topicArn; } @@ -282,7 +281,7 @@ export abstract class TopicRef extends cdk.Construct implements events.IEventRul * @param bucketArn The ARN of the bucket sending the notifications * @param bucketId A unique ID of the bucket */ - public asBucketNotificationDestination(bucketArn: cdk.Arn, bucketId: string): s3n.BucketNotificationDestinationProps { + public asBucketNotificationDestination(bucketArn: string, bucketId: string): s3n.BucketNotificationDestinationProps { // allow this bucket to sns:publish to this topic (if it doesn't already have a permission) if (!this.notifyingBuckets.has(bucketId)) { @@ -307,8 +306,8 @@ export abstract class TopicRef extends cdk.Construct implements events.IEventRul * An imported topic */ class ImportedTopic extends TopicRef { - public readonly topicArn: TopicArn; - public readonly topicName: TopicName; + public readonly topicArn: string; + public readonly topicName: string; protected autoCreatePolicy: boolean = false; @@ -323,8 +322,8 @@ class ImportedTopic extends TopicRef { * Reference to an external topic. */ export interface TopicRefProps { - topicArn: TopicArn; - topicName: TopicName; + topicArn: string; + topicName: string; } /** diff --git a/packages/@aws-cdk/aws-sns/lib/topic.ts b/packages/@aws-cdk/aws-sns/lib/topic.ts index 66bae18547c59..2e53526372bf5 100644 --- a/packages/@aws-cdk/aws-sns/lib/topic.ts +++ b/packages/@aws-cdk/aws-sns/lib/topic.ts @@ -1,5 +1,5 @@ import { Construct, } from '@aws-cdk/cdk'; -import { cloudformation, TopicArn, TopicName } from './sns.generated'; +import { cloudformation } from './sns.generated'; import { TopicRef } from './topic-ref'; /** @@ -29,8 +29,8 @@ export interface TopicProps { * A new SNS topic */ export class Topic extends TopicRef { - public readonly topicArn: TopicArn; - public readonly topicName: TopicName; + public readonly topicArn: string; + public readonly topicName: string; protected readonly autoCreatePolicy: boolean = true; diff --git a/packages/@aws-cdk/aws-sns/test/test.sns.ts b/packages/@aws-cdk/aws-sns/test/test.sns.ts index 6ad8f4a689274..f4abb7a274e47 100644 --- a/packages/@aws-cdk/aws-sns/test/test.sns.ts +++ b/packages/@aws-cdk/aws-sns/test/test.sns.ts @@ -509,7 +509,7 @@ export = { topic.addToResourcePolicy(new cdk.PolicyStatement() .addAllResources() .addActions('sns:*') - .addPrincipal(new cdk.ArnPrincipal(new cdk.Arn('arn')))); + .addPrincipal(new cdk.ArnPrincipal('arn'))); // THEN expect(stack).to(haveResource('AWS::SNS::TopicPolicy', { @@ -699,7 +699,7 @@ export = { const topic = new sns.Topic(stack, 'MyTopic'); - const bucketArn = new cdk.Arn('arn:bucket'); + const bucketArn = 'arn:bucket'; const bucketId = 'bucketId'; const dest1 = topic.asBucketNotificationDestination(bucketArn, bucketId); @@ -715,7 +715,7 @@ export = { test.deepEqual(dest2.type, s3n.BucketNotificationDestinationType.Topic); // another bucket will be added to the topic policy - const dest3 = topic.asBucketNotificationDestination(new cdk.Arn('bucket2'), 'bucket2'); + const dest3 = topic.asBucketNotificationDestination('bucket2', 'bucket2'); test.deepEqual(resolve(dest3.arn), resolve(topic.topicArn)); test.deepEqual(dest3.type, s3n.BucketNotificationDestinationType.Topic); diff --git a/packages/@aws-cdk/aws-sqs/lib/queue-ref.ts b/packages/@aws-cdk/aws-sqs/lib/queue-ref.ts index 9d9728fef03fc..d43115a0058b5 100644 --- a/packages/@aws-cdk/aws-sqs/lib/queue-ref.ts +++ b/packages/@aws-cdk/aws-sqs/lib/queue-ref.ts @@ -2,7 +2,6 @@ import kms = require('@aws-cdk/aws-kms'); import s3n = require('@aws-cdk/aws-s3-notifications'); import cdk = require('@aws-cdk/cdk'); import { QueuePolicy } from './policy'; -import { QueueArn, QueueUrl } from './sqs.generated'; /** * Reference to a new or existing Amazon SQS queue @@ -18,12 +17,12 @@ export abstract class QueueRef extends cdk.Construct implements s3n.IBucketNotif /** * The ARN of this queue */ - public abstract readonly queueArn: QueueArn; + public abstract readonly queueArn: string; /** * The URL of this queue */ - public abstract readonly queueUrl: QueueUrl; + public abstract readonly queueUrl: string; /** * If this queue is server-side encrypted, this is the KMS encryption key. @@ -49,10 +48,10 @@ export abstract class QueueRef extends cdk.Construct implements s3n.IBucketNotif */ public export(): QueueRefProps { return { - queueArn: new QueueArn(new cdk.Output(this, 'QueueArn', { value: this.queueArn }).makeImportValue()), - queueUrl: new QueueUrl(new cdk.Output(this, 'QueueUrl', { value: this.queueUrl }).makeImportValue()), + queueArn: new cdk.Output(this, 'QueueArn', { value: this.queueArn }).makeImportValue().toString(), + queueUrl: new cdk.Output(this, 'QueueUrl', { value: this.queueUrl }).makeImportValue().toString(), keyArn: this.encryptionMasterKey - ? new kms.KeyArn(new cdk.Output(this, 'KeyArn', { value: this.encryptionMasterKey.keyArn }).makeImportValue()) + ? new cdk.Output(this, 'KeyArn', { value: this.encryptionMasterKey.keyArn }).makeImportValue().toString() : undefined }; } @@ -80,7 +79,7 @@ export abstract class QueueRef extends cdk.Construct implements s3n.IBucketNotif * @param bucketArn The ARN of the notifying bucket. * @param bucketId A unique ID for the notifying bucket. */ - public asBucketNotificationDestination(bucketArn: cdk.Arn, bucketId: string): s3n.BucketNotificationDestinationProps { + public asBucketNotificationDestination(bucketArn: string, bucketId: string): s3n.BucketNotificationDestinationProps { if (!this.notifyingBuckets.has(bucketId)) { this.addToResourcePolicy(new cdk.PolicyStatement() .addServicePrincipal('s3.amazonaws.com') @@ -119,25 +118,25 @@ export interface QueueRefProps { /** * The ARN of the queue. */ - queueArn: QueueArn; + queueArn: string; /** * The URL of the queue. */ - queueUrl: QueueUrl; + queueUrl: string; /** * KMS encryption key, if this queue is server-side encrypted by a KMS key. */ - keyArn?: kms.KeyArn; + keyArn?: string; } /** * A queue that has been imported */ class ImportedQueue extends QueueRef { - public readonly queueArn: QueueArn; - public readonly queueUrl: QueueUrl; + public readonly queueArn: string; + public readonly queueUrl: string; public readonly encryptionMasterKey?: kms.EncryptionKeyRef; protected readonly autoCreatePolicy = false; diff --git a/packages/@aws-cdk/aws-sqs/lib/queue.ts b/packages/@aws-cdk/aws-sqs/lib/queue.ts index 099e4ac3d6564..3750b2e667da5 100644 --- a/packages/@aws-cdk/aws-sqs/lib/queue.ts +++ b/packages/@aws-cdk/aws-sqs/lib/queue.ts @@ -1,7 +1,7 @@ import kms = require('@aws-cdk/aws-kms'); import cdk = require('@aws-cdk/cdk'); import { QueueRef } from './queue-ref'; -import { cloudformation, QueueArn, QueueName, QueueUrl } from './sqs.generated'; +import { cloudformation } from './sqs.generated'; import { validateProps } from './validate-props'; /** @@ -183,17 +183,17 @@ export class Queue extends QueueRef { /** * The ARN of this queue */ - public readonly queueArn: QueueArn; + public readonly queueArn: string; /** * The name of this queue */ - public readonly queueName: QueueName; + public readonly queueName: string; /** * The URL of this queue */ - public readonly queueUrl: QueueUrl; + public readonly queueUrl: string; /** * If this queue is encrypted, this is the KMS key. @@ -245,7 +245,7 @@ export class Queue extends QueueRef { if (encryption === QueueEncryption.KmsManaged) { const masterKey = kms.EncryptionKey.import(this, 'Key', { - keyArn: new kms.KeyArn('alias/aws/sqs') + keyArn: 'alias/aws/sqs' }); return { @@ -311,6 +311,6 @@ interface FifoProps { } interface EncryptionProps { - readonly kmsMasterKeyId?: string | kms.KeyArn; + readonly kmsMasterKeyId?: string; readonly kmsDataKeyReusePeriodSeconds?: number; } diff --git a/packages/@aws-cdk/aws-sqs/test/test.sqs.ts b/packages/@aws-cdk/aws-sqs/test/test.sqs.ts index 9d18c53027fd0..325b8fe8e1716 100644 --- a/packages/@aws-cdk/aws-sqs/test/test.sqs.ts +++ b/packages/@aws-cdk/aws-sqs/test/test.sqs.ts @@ -1,7 +1,7 @@ import { expect, haveResource } from '@aws-cdk/assert'; import kms = require('@aws-cdk/aws-kms'); import s3 = require('@aws-cdk/aws-s3'); -import { Arn, ArnPrincipal, PolicyStatement, resolve, Stack } from '@aws-cdk/cdk'; +import { ArnPrincipal, PolicyStatement, resolve, Stack } from '@aws-cdk/cdk'; import { Test } from 'nodeunit'; import sqs = require('../lib'); diff --git a/packages/@aws-cdk/cdk/lib/cloudformation/output.ts b/packages/@aws-cdk/cdk/lib/cloudformation/output.ts index c3e8e298c10c3..0e1645d3ffef8 100644 --- a/packages/@aws-cdk/cdk/lib/cloudformation/output.ts +++ b/packages/@aws-cdk/cdk/lib/cloudformation/output.ts @@ -120,7 +120,7 @@ export class Output extends StackElement { }; } - public get ref(): Token { + public get ref(): string { throw new Error('Outputs cannot be referenced'); } } diff --git a/packages/@aws-cdk/cdk/lib/cloudformation/parameter.ts b/packages/@aws-cdk/cdk/lib/cloudformation/parameter.ts index c578d86818bd2..3e0b1e781380d 100644 --- a/packages/@aws-cdk/cdk/lib/cloudformation/parameter.ts +++ b/packages/@aws-cdk/cdk/lib/cloudformation/parameter.ts @@ -1,6 +1,6 @@ import { Construct } from '../core/construct'; import { Token } from '../core/tokens'; -import { Referenceable } from './stack'; +import { Ref, Referenceable } from './stack'; export interface ParameterProps { /** @@ -89,7 +89,7 @@ export class Parameter extends Referenceable { constructor(parent: Construct, name: string, props: ParameterProps) { super(parent, name); this.properties = props; - this.value = this.ref; + this.value = new Ref(this); } public toCloudFormation(): object { diff --git a/packages/@aws-cdk/cdk/lib/cloudformation/resource.ts b/packages/@aws-cdk/cdk/lib/cloudformation/resource.ts index 208913893f447..65266bf9fe951 100644 --- a/packages/@aws-cdk/cdk/lib/cloudformation/resource.ts +++ b/packages/@aws-cdk/cdk/lib/cloudformation/resource.ts @@ -1,10 +1,9 @@ import { Construct } from '../core/construct'; -import { Token } from '../core/tokens'; import { capitalizePropertyNames, ignoreEmpty } from '../core/util'; import { CloudFormationToken } from './cloudformation-token'; import { Condition } from './condition'; import { CreationPolicy, DeletionPolicy, UpdatePolicy } from './resource-policy'; -import { IDependable, StackElement } from './stack'; +import { IDependable, Referenceable, StackElement } from './stack'; export interface ResourceProps { /** @@ -21,7 +20,7 @@ export interface ResourceProps { /** * Represents a CloudFormation resource. */ -export class Resource extends StackElement { +export class Resource extends Referenceable { /** * A decoration used to create a CloudFormation attribute property. * @param customName Custom name for the attribute (default is the name of the property) @@ -82,15 +81,8 @@ export class Resource extends StackElement { * in case there is no generated attribute. * @param attributeName The name of the attribute. */ - public getAtt(attributeName: string): Token { - return new CloudFormationToken({ 'Fn::GetAtt': [this.logicalId, attributeName] }, `${this.logicalId}.${attributeName}`); - } - - /** - * Returns a token that resolves to `{ "Ref": LogicalID }` - */ - public get ref() { - return new CloudFormationToken({ Ref: this.logicalId }); + public getAtt(attributeName: string): string { + return new CloudFormationToken({ 'Fn::GetAtt': [this.logicalId, attributeName] }, `${this.logicalId}.${attributeName}`).toString(); } /** diff --git a/packages/@aws-cdk/cdk/lib/cloudformation/secret.ts b/packages/@aws-cdk/cdk/lib/cloudformation/secret.ts index 53f2f62ae545e..1d495b7542c06 100644 --- a/packages/@aws-cdk/cdk/lib/cloudformation/secret.ts +++ b/packages/@aws-cdk/cdk/lib/cloudformation/secret.ts @@ -1,4 +1,4 @@ -import { Construct } from "../core/construct"; +import { Construct } from '../core/construct'; import { Token } from '../core/tokens'; import { Parameter } from './parameter'; @@ -12,9 +12,7 @@ import { Parameter } from './parameter'; * * However, you can also just pass in values, like any other token: `new Secret('bla')` */ -export class Secret extends Token { - -} +export class Secret extends Token { } export interface SecretProps { /** @@ -91,6 +89,6 @@ export class SecretParameter extends Construct { noEcho: true, }); - this.value = param.ref; + this.value = new Secret(param.ref); } } diff --git a/packages/@aws-cdk/cdk/lib/cloudformation/stack.ts b/packages/@aws-cdk/cdk/lib/cloudformation/stack.ts index b24ee91e4dbcb..4e2dd4235b928 100644 --- a/packages/@aws-cdk/cdk/lib/cloudformation/stack.ts +++ b/packages/@aws-cdk/cdk/lib/cloudformation/stack.ts @@ -405,8 +405,8 @@ export abstract class Referenceable extends StackElement { /** * Returns a token to a CloudFormation { Ref } that references this entity based on it's logical ID. */ - public get ref(): Token { - return new Ref(this); + public get ref(): string { + return new Ref(this).toString(); } } diff --git a/packages/@aws-cdk/cdk/lib/cloudformation/tag.ts b/packages/@aws-cdk/cdk/lib/cloudformation/tag.ts index 1b113049f5825..388df09bc3286 100644 --- a/packages/@aws-cdk/cdk/lib/cloudformation/tag.ts +++ b/packages/@aws-cdk/cdk/lib/cloudformation/tag.ts @@ -1,5 +1,3 @@ -import { Token } from '../core/tokens'; - /** * @link http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-resource-tags.html */ @@ -7,10 +5,10 @@ export interface Tag { /** * @link http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-resource-tags.html#cfn-resource-tags-key */ - key: string | Token; + key: string; /** * @link http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-resource-tags.html#cfn-resource-tags-value */ - value: string | Token; + value: string; } \ No newline at end of file diff --git a/packages/@aws-cdk/cdk/test/cloudformation/test.resource.ts b/packages/@aws-cdk/cdk/test/cloudformation/test.resource.ts index ea41cb5e43a66..1b6f81d89d2a9 100644 --- a/packages/@aws-cdk/cdk/test/cloudformation/test.resource.ts +++ b/packages/@aws-cdk/cdk/test/cloudformation/test.resource.ts @@ -345,7 +345,7 @@ export = { const stack = new Stack(); const r = new Resource(stack, 'MyResource', { type: 'R' }); - test.deepEqual(resolve(r), {}); + test.deepEqual(resolve(r.ref), { Ref: 'MyResource' }); test.done(); } }; diff --git a/packages/@aws-cdk/runtime-values/lib/rtv.ts b/packages/@aws-cdk/runtime-values/lib/rtv.ts index 7900f7133e7d8..390d512ca685d 100644 --- a/packages/@aws-cdk/runtime-values/lib/rtv.ts +++ b/packages/@aws-cdk/runtime-values/lib/rtv.ts @@ -44,17 +44,17 @@ export class RuntimeValue extends cdk.Construct { /** * The name of the runtime parameter. */ - public readonly parameterName: ParameterName; + public readonly parameterName: string; /** * The ARN fo the SSM parameter used for this runtime value. */ - public readonly parameterArn: cdk.Arn; + public readonly parameterArn: string; constructor(parent: cdk.Construct, name: string, props: RuntimeValueProps) { super(parent, name); - this.parameterName = new cdk.FnConcat('/rtv/', new cdk.AwsStackName(), '/', props.package, '/', name); + this.parameterName = `/rtv/${new cdk.AwsStackName()}/${props.package}/${name}`; new ssm.cloudformation.ParameterResource(this, 'Parameter', { parameterName: this.parameterName, @@ -62,7 +62,7 @@ export class RuntimeValue extends cdk.Construct { value: props.value, }); - this.parameterArn = cdk.Arn.fromComponents({ + this.parameterArn = cdk.ArnUtils.fromComponents({ service: 'ssm', resource: 'parameter', resourceName: this.parameterName @@ -84,11 +84,4 @@ export class RuntimeValue extends cdk.Construct { .addResource(this.parameterArn) .addActions(...RuntimeValue.SSM_READ_ACTIONS)); } -} - -/** - * The full name of the runtime value's SSM parameter. - */ -export class ParameterName extends cdk.Token { - -} +} \ No newline at end of file diff --git a/tools/cdk-build-tools/bin/cdk-build.ts b/tools/cdk-build-tools/bin/cdk-build.ts index b2188680a475c..00298183c3c66 100644 --- a/tools/cdk-build-tools/bin/cdk-build.ts +++ b/tools/cdk-build-tools/bin/cdk-build.ts @@ -46,7 +46,6 @@ const buildTimer = timers.start('Total time'); main().then(() => { buildTimer.end(); - process.stdout.write(`Build complete. ${timers.display()}\n`); }).catch(e => { buildTimer.end(); process.stderr.write(`${e.toString()}\n`); diff --git a/tools/cfn2ts/lib/index.ts b/tools/cfn2ts/lib/index.ts index 12bfa2e9b8107..435e60308b0e6 100644 --- a/tools/cfn2ts/lib/index.ts +++ b/tools/cfn2ts/lib/index.ts @@ -17,8 +17,6 @@ export default async function(scope: string, outPath: string, force: boolean) { const generator = new CodeGenerator(name, spec); if (!force && await generator.upToDate(outPath)) { - // tslint:disable-next-line:no-console - console.log('Generated code already up-to-date: %s', colors.green(path.join(outPath, generator.outputFile))); return; } generator.emitCode(); From 8ac4942fb6b4e07e6e0da18a116335dba1c610a0 Mon Sep 17 00:00:00 2001 From: Elad Ben-Israel Date: Mon, 17 Sep 2018 21:49:42 +0300 Subject: [PATCH 03/13] Fix breaks after merge --- packages/@aws-cdk/aws-apigateway/lib/deployment.ts | 10 +++++----- .../@aws-cdk/aws-apigateway/lib/integrations/aws.ts | 2 +- packages/@aws-cdk/aws-apigateway/lib/method.ts | 12 ++++++------ packages/@aws-cdk/aws-apigateway/lib/resource.ts | 8 ++++---- packages/@aws-cdk/aws-apigateway/lib/restapi-ref.ts | 9 ++++----- packages/@aws-cdk/aws-apigateway/lib/restapi.ts | 10 +++++----- packages/@aws-cdk/aws-apigateway/lib/stage.ts | 4 ++-- .../@aws-cdk/aws-apigateway/test/test.restapi.ts | 8 ++++---- .../aws-rds/lib/cluster-parameter-group-ref.ts | 10 ++++------ .../@aws-cdk/aws-rds/lib/cluster-parameter-group.ts | 4 ++-- 10 files changed, 37 insertions(+), 40 deletions(-) diff --git a/packages/@aws-cdk/aws-apigateway/lib/deployment.ts b/packages/@aws-cdk/aws-apigateway/lib/deployment.ts index f8161123633eb..33b214120d425 100644 --- a/packages/@aws-cdk/aws-apigateway/lib/deployment.ts +++ b/packages/@aws-cdk/aws-apigateway/lib/deployment.ts @@ -1,6 +1,6 @@ import cdk = require('@aws-cdk/cdk'); import crypto = require('crypto'); -import { cloudformation, DeploymentId } from './apigateway.generated'; +import { cloudformation } from './apigateway.generated'; import { RestApiRef } from './restapi-ref'; export interface DeploymentProps { @@ -55,7 +55,7 @@ export interface DeploymentProps { * automatically for the `restApi.latestDeployment` deployment. */ export class Deployment extends cdk.Construct implements cdk.IDependable { - public readonly deploymentId: DeploymentId; + public readonly deploymentId: string; public readonly api: RestApiRef; /** @@ -78,7 +78,7 @@ export class Deployment extends cdk.Construct implements cdk.IDependable { } this.api = props.api; - this.deploymentId = new DeploymentId(() => this.resource.ref); + this.deploymentId = new cdk.Token(() => this.resource.deploymentId).toString(); this.dependencyElements.push(this.resource); } @@ -142,13 +142,13 @@ class LatestDeploymentResource extends cloudformation.DeploymentResource { * Returns a lazy reference to this resource (evaluated only upon synthesis). */ public get ref() { - return new DeploymentId(() => ({ Ref: this.lazyLogicalId })); + return new cdk.Token(() => ({ Ref: this.lazyLogicalId })).toString(); } /** * Does nothing. */ - public set ref(_v: DeploymentId) { + public set ref(_v: string) { return; } diff --git a/packages/@aws-cdk/aws-apigateway/lib/integrations/aws.ts b/packages/@aws-cdk/aws-apigateway/lib/integrations/aws.ts index feebddd35aba4..7a70b330b4806 100644 --- a/packages/@aws-cdk/aws-apigateway/lib/integrations/aws.ts +++ b/packages/@aws-cdk/aws-apigateway/lib/integrations/aws.ts @@ -68,7 +68,7 @@ export class AwsIntegration extends Integration { super({ type, integrationHttpMethod: 'POST', - uri: cdk.Arn.fromComponents({ + uri: cdk.ArnUtils.fromComponents({ service: 'apigateway', account: backend, resource: apiType, diff --git a/packages/@aws-cdk/aws-apigateway/lib/method.ts b/packages/@aws-cdk/aws-apigateway/lib/method.ts index a1453fa771ae0..aa46587eba870 100644 --- a/packages/@aws-cdk/aws-apigateway/lib/method.ts +++ b/packages/@aws-cdk/aws-apigateway/lib/method.ts @@ -1,5 +1,5 @@ import cdk = require('@aws-cdk/cdk'); -import { AuthorizerId, cloudformation, MethodId } from './apigateway.generated'; +import { cloudformation } from './apigateway.generated'; import { Integration } from './integration'; import { MockIntegration } from './integrations/mock'; import { IRestApiResource } from './resource'; @@ -26,7 +26,7 @@ export interface MethodOptions { * NOTE: in the future this will be replaced with an `AuthorizerRef` * construct. */ - authorizerId?: AuthorizerId; + authorizerId?: string; /** * Indicates whether the method requires clients to submit a valid API key. @@ -65,7 +65,7 @@ export interface MethodProps { } export class Method extends cdk.Construct { - public readonly methodId: MethodId; + public readonly methodId: string; public readonly httpMethod: string; public readonly resource: IRestApiResource; public readonly restApi: RestApi; @@ -115,7 +115,7 @@ export class Method extends cdk.Construct { * NOTE: {stage} will refer to the `restApi.deploymentStage`, which will * automatically set if auto-deploy is enabled. */ - public get methodArn(): cdk.Arn { + public get methodArn(): string { if (!this.restApi.deploymentStage) { throw new Error('There is no stage associated with this restApi. Either use `autoDeploy` or explicitly assign `deploymentStage`'); } @@ -128,7 +128,7 @@ export class Method extends cdk.Construct { * Returns an execute-api ARN for this method's "test-invoke-stage" stage. * This stage is used by the AWS Console UI when testing the method. */ - public get testMethodArn(): cdk.Arn { + public get testMethodArn(): string { return this.restApi.executeApiArn(this.httpMethod, this.resource.resourcePath, 'test-invoke-stage'); } @@ -156,7 +156,7 @@ export class Method extends cdk.Construct { credentials = options.credentialsRole.roleArn; } else if (options.credentialsPassthrough) { // arn:aws:iam::*:user/* - credentials = cdk.Arn.fromComponents({ service: 'iam', region: '', account: '*', resource: 'user', sep: '/', resourceName: '*' }); + credentials = cdk.ArnUtils.fromComponents({ service: 'iam', region: '', account: '*', resource: 'user', sep: '/', resourceName: '*' }); } return { diff --git a/packages/@aws-cdk/aws-apigateway/lib/resource.ts b/packages/@aws-cdk/aws-apigateway/lib/resource.ts index 447cffbdc1aee..209e2024a8cbc 100644 --- a/packages/@aws-cdk/aws-apigateway/lib/resource.ts +++ b/packages/@aws-cdk/aws-apigateway/lib/resource.ts @@ -1,5 +1,5 @@ import cdk = require('@aws-cdk/cdk'); -import { cloudformation, ResourceId } from './apigateway.generated'; +import { cloudformation } from './apigateway.generated'; import { Integration } from './integration'; import { Method, MethodOptions } from './method'; import { RestApi } from './restapi'; @@ -18,7 +18,7 @@ export interface IRestApiResource { /** * The ID of the resource. */ - readonly resourceId: ResourceId; + readonly resourceId: string; /** * The full path of this resuorce. @@ -85,7 +85,7 @@ export interface ResourceProps extends ResourceOptions { export class Resource extends cdk.Construct implements IRestApiResource { public readonly resourceApi: RestApi; - public readonly resourceId: ResourceId; + public readonly resourceId: string; public readonly resourcePath: string; public readonly defaultIntegration?: Integration; public readonly defaultMethodOptions?: MethodOptions; @@ -102,7 +102,7 @@ export class Resource extends cdk.Construct implements IRestApiResource { }; const resource = new cloudformation.Resource(this, 'Resource', resourceProps); - this.resourceId = resource.ref; + this.resourceId = resource.resourceId; this.resourceApi = props.parent.resourceApi; // render resource path (special case for root) diff --git a/packages/@aws-cdk/aws-apigateway/lib/restapi-ref.ts b/packages/@aws-cdk/aws-apigateway/lib/restapi-ref.ts index e5212518f1852..f039e0f2c42f4 100644 --- a/packages/@aws-cdk/aws-apigateway/lib/restapi-ref.ts +++ b/packages/@aws-cdk/aws-apigateway/lib/restapi-ref.ts @@ -1,11 +1,10 @@ import cdk = require('@aws-cdk/cdk'); -import { RestApiId } from './apigateway.generated'; export interface RestApiRefProps { /** * The REST API ID of an existing REST API resource. */ - restApiId: RestApiId; + restApiId: string; } export abstract class RestApiRef extends cdk.Construct { @@ -23,7 +22,7 @@ export abstract class RestApiRef extends cdk.Construct { /** * The ID of this API Gateway RestApi. */ - public readonly abstract restApiId: RestApiId; + public readonly abstract restApiId: string; /** * Exports a REST API resource from this stack. @@ -31,13 +30,13 @@ export abstract class RestApiRef extends cdk.Construct { */ public export(): RestApiRefProps { return { - restApiId: new RestApiId(new cdk.Output(this, 'RestApiId', { value: this.restApiId }).makeImportValue()), + restApiId: new cdk.Output(this, 'RestApiId', { value: this.restApiId }).makeImportValue().toString() }; } } class ImportedRestApi extends RestApiRef { - public restApiId: RestApiId; + public restApiId: string; constructor(parent: cdk.Construct, id: string, props: RestApiRefProps) { super(parent, id); diff --git a/packages/@aws-cdk/aws-apigateway/lib/restapi.ts b/packages/@aws-cdk/aws-apigateway/lib/restapi.ts index 3a87dbb5e9bec..16137bd7223ed 100644 --- a/packages/@aws-cdk/aws-apigateway/lib/restapi.ts +++ b/packages/@aws-cdk/aws-apigateway/lib/restapi.ts @@ -1,6 +1,6 @@ import iam = require('@aws-cdk/aws-iam'); import cdk = require('@aws-cdk/cdk'); -import { cloudformation, ResourceId, RestApiId } from './apigateway.generated'; +import { cloudformation } from './apigateway.generated'; import { Deployment } from './deployment'; import { Integration } from './integration'; import { Method, MethodOptions } from './method'; @@ -139,7 +139,7 @@ export class RestApi extends RestApiRef implements cdk.IDependable { /** * The ID of this API Gateway RestApi. */ - public readonly restApiId: RestApiId; + public readonly restApiId: string; /** * API Gateway deployment that represents the latest changes of the API. @@ -216,7 +216,7 @@ export class RestApi extends RestApiRef implements cdk.IDependable { defaultIntegration: props.defaultIntegration, defaultMethodOptions: props.defaultMethodOptions, resourceApi: this, - resourceId: new ResourceId(resource.restApiRootResourceId), + resourceId: resource.restApiRootResourceId, resourcePath: '/' }; } @@ -258,7 +258,7 @@ export class RestApi extends RestApiRef implements cdk.IDependable { method = '*'; } - return cdk.Arn.fromComponents({ + return cdk.ArnUtils.fromComponents({ service: 'execute-api', resource: this.restApiId, sep: '/', @@ -315,7 +315,7 @@ export class RestApi extends RestApiRef implements cdk.IDependable { private configureCloudWatchRole(apiResource: cloudformation.RestApiResource) { const role = new iam.Role(this, 'CloudWatchRole', { assumedBy: new cdk.ServicePrincipal('apigateway.amazonaws.com'), - managedPolicyArns: [ cdk.Arn.fromComponents({ + managedPolicyArns: [ cdk.ArnUtils.fromComponents({ service: 'iam', region: '', account: 'aws', diff --git a/packages/@aws-cdk/aws-apigateway/lib/stage.ts b/packages/@aws-cdk/aws-apigateway/lib/stage.ts index fd0026c661461..0d50d3144e9c8 100644 --- a/packages/@aws-cdk/aws-apigateway/lib/stage.ts +++ b/packages/@aws-cdk/aws-apigateway/lib/stage.ts @@ -1,5 +1,5 @@ import cdk = require('@aws-cdk/cdk'); -import { cloudformation, StageName } from './apigateway.generated'; +import { cloudformation } from './apigateway.generated'; import { Deployment } from './deployment'; import { RestApiRef } from './restapi-ref'; import { parseMethodOptionsPath } from './util'; @@ -127,7 +127,7 @@ export interface MethodDeploymentOptions { } export class Stage extends cdk.Construct implements cdk.IDependable { - public readonly stageName: StageName; + public readonly stageName: string; public readonly dependencyElements = new Array(); private readonly restApi: RestApiRef; diff --git a/packages/@aws-cdk/aws-apigateway/test/test.restapi.ts b/packages/@aws-cdk/aws-apigateway/test/test.restapi.ts index ddaf17380bf9c..21c18bba1759c 100644 --- a/packages/@aws-cdk/aws-apigateway/test/test.restapi.ts +++ b/packages/@aws-cdk/aws-apigateway/test/test.restapi.ts @@ -366,7 +366,7 @@ export = { // WHEN const imported = apigateway.RestApi.import(stack, 'imported-api', { - restApiId: new apigateway.RestApiId('api-rxt4498f') + restApiId: 'api-rxt4498f' }); const exported = imported.export(); @@ -528,7 +528,7 @@ export = { // GIVEN const stack = new cdk.Stack(); const cloneFrom = apigateway.RestApi.import(stack, 'RestApi', { - restApiId: new apigateway.RestApiId('foobar') + restApiId: 'foobar' }); // WHEN @@ -580,7 +580,7 @@ export = { const api = new apigateway.RestApi(stack, 'myapi', { defaultIntegration: rootInteg, defaultMethodOptions: { - authorizerId: new apigateway.AuthorizerId('AUTHID'), + authorizerId: 'AUTHID', authorizationType: apigateway.AuthorizationType.IAM, } }); @@ -599,7 +599,7 @@ export = { const child2 = api.root.addResource('child2', { defaultIntegration: new apigateway.MockIntegration(), defaultMethodOptions: { - authorizerId: new apigateway.AuthorizerId('AUTHID2'), + authorizerId: 'AUTHID2', } }); diff --git a/packages/@aws-cdk/aws-rds/lib/cluster-parameter-group-ref.ts b/packages/@aws-cdk/aws-rds/lib/cluster-parameter-group-ref.ts index 342a826649eb7..045a93ced4309 100644 --- a/packages/@aws-cdk/aws-rds/lib/cluster-parameter-group-ref.ts +++ b/packages/@aws-cdk/aws-rds/lib/cluster-parameter-group-ref.ts @@ -1,5 +1,4 @@ import cdk = require('@aws-cdk/cdk'); -import { DBClusterParameterGroupName } from './rds.generated'; /** * A cluster parameter group @@ -15,15 +14,14 @@ export abstract class ClusterParameterGroupRef extends cdk.Construct { /** * Name of this parameter group */ - public abstract readonly parameterGroupName: DBClusterParameterGroupName; + public abstract readonly parameterGroupName: string; /** * Export this parameter group */ public export(): ClusterParameterGroupRefProps { return { - parameterGroupName: new DBClusterParameterGroupName( - new cdk.Output(this, 'ParameterGroupName', { value: this.parameterGroupName }).makeImportValue()) + parameterGroupName: new cdk.Output(this, 'ParameterGroupName', { value: this.parameterGroupName }).makeImportValue().toString() }; } } @@ -32,14 +30,14 @@ export abstract class ClusterParameterGroupRef extends cdk.Construct { * Properties to reference a cluster parameter group */ export interface ClusterParameterGroupRefProps { - parameterGroupName: DBClusterParameterGroupName; + parameterGroupName: string; } /** * An imported cluster parameter group */ class ImportedClusterParameterGroup extends ClusterParameterGroupRef { - public readonly parameterGroupName: DBClusterParameterGroupName; + public readonly parameterGroupName: string; constructor(parent: cdk.Construct, id: string, props: ClusterParameterGroupRefProps) { super(parent, id); diff --git a/packages/@aws-cdk/aws-rds/lib/cluster-parameter-group.ts b/packages/@aws-cdk/aws-rds/lib/cluster-parameter-group.ts index 4fb81a8106c12..61f9b74430239 100644 --- a/packages/@aws-cdk/aws-rds/lib/cluster-parameter-group.ts +++ b/packages/@aws-cdk/aws-rds/lib/cluster-parameter-group.ts @@ -1,7 +1,7 @@ import cdk = require('@aws-cdk/cdk'); import { ClusterParameterGroupRef } from './cluster-parameter-group-ref'; import { Parameters } from './props'; -import { cloudformation, DBClusterParameterGroupName } from './rds.generated'; +import { cloudformation } from './rds.generated'; /** * Properties for a cluster parameter group @@ -27,7 +27,7 @@ export interface ClusterParameterGroupProps { * Defina a cluster parameter group */ export class ClusterParameterGroup extends ClusterParameterGroupRef { - public readonly parameterGroupName: DBClusterParameterGroupName; + public readonly parameterGroupName: string; private readonly parameters: Parameters = {}; constructor(parent: cdk.Construct, id: string, props: ClusterParameterGroupProps) { From 73b5a377c380a639320dbafad617b5a4e2c9c7b0 Mon Sep 17 00:00:00 2001 From: Elad Ben-Israel Date: Mon, 17 Sep 2018 22:10:30 +0300 Subject: [PATCH 04/13] Use ref instead of getatt for subnet id --- packages/@aws-cdk/aws-ec2/lib/vpc.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/@aws-cdk/aws-ec2/lib/vpc.ts b/packages/@aws-cdk/aws-ec2/lib/vpc.ts index 07181f641e01b..5f0bf868ddb2a 100644 --- a/packages/@aws-cdk/aws-ec2/lib/vpc.ts +++ b/packages/@aws-cdk/aws-ec2/lib/vpc.ts @@ -479,7 +479,7 @@ export class VpcSubnet extends VpcSubnetRef implements cdk.ITaggable { mapPublicIpOnLaunch: props.mapPublicIpOnLaunch, tags: this.tags, }); - this.subnetId = subnet.subnetVpcId; + this.subnetId = subnet.subnetId; const table = new cloudformation.RouteTableResource(this, 'RouteTable', { vpcId: props.vpcId, tags: new cdk.TagManager(this), From acb96b73e1b4218b1c53ddaadbf027f8da1773af Mon Sep 17 00:00:00 2001 From: Elad Ben-Israel Date: Mon, 17 Sep 2018 22:30:19 +0300 Subject: [PATCH 05/13] Update expecations --- .../test/integ.rtv.lambda.expected.json | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/packages/@aws-cdk/runtime-values/test/integ.rtv.lambda.expected.json b/packages/@aws-cdk/runtime-values/test/integ.rtv.lambda.expected.json index 6d0c2a5f1c8d1..af3bea98aa392 100644 --- a/packages/@aws-cdk/runtime-values/test/integ.rtv.lambda.expected.json +++ b/packages/@aws-cdk/runtime-values/test/integ.rtv.lambda.expected.json @@ -78,14 +78,18 @@ ":", "parameter", "/", - "/rtv/", { - "Ref": "AWS::StackName" - }, - "/", - "com.myorg", - "/", - "MyQueueURL" + "Fn::Join": [ + "", + [ + "/rtv/", + { + "Ref": "AWS::StackName" + }, + "/com.myorg/MyQueueURL" + ] + ] + } ] ] } @@ -144,10 +148,7 @@ { "Ref": "AWS::StackName" }, - "/", - "com.myorg", - "/", - "MyQueueURL" + "/com.myorg/MyQueueURL" ] ] } From b9f52a70fcde890650851c718e26ba9d39352363 Mon Sep 17 00:00:00 2001 From: Elad Ben-Israel Date: Mon, 17 Sep 2018 23:37:37 +0300 Subject: [PATCH 06/13] Fix codebuild tests --- .../test/integ.caching.expected.json | 47 +-- .../test/integ.project-bucket.expected.json | 47 +-- .../test/integ.project-events.expected.json | 47 +-- .../aws-codebuild/test/test.codebuild.ts | 305 ++++++++++-------- 4 files changed, 244 insertions(+), 202 deletions(-) diff --git a/packages/@aws-cdk/aws-codebuild/test/integ.caching.expected.json b/packages/@aws-cdk/aws-codebuild/test/integ.caching.expected.json index 1b7782ac70f96..42e04c47317a6 100644 --- a/packages/@aws-cdk/aws-codebuild/test/integ.caching.expected.json +++ b/packages/@aws-cdk/aws-codebuild/test/integ.caching.expected.json @@ -89,9 +89,16 @@ ":", "log-group", ":", - "/aws/codebuild/", { - "Ref": "MyProject39F7B0AE" + "Fn::Join": [ + "", + [ + "/aws/codebuild/", + { + "Ref": "MyProject39F7B0AE" + } + ] + ] } ] ] @@ -100,28 +107,28 @@ "Fn::Join": [ "", [ + "arn", + ":", + { + "Ref": "AWS::Partition" + }, + ":", + "logs", + ":", + { + "Ref": "AWS::Region" + }, + ":", + { + "Ref": "AWS::AccountId" + }, + ":", + "log-group", + ":", { "Fn::Join": [ "", [ - "arn", - ":", - { - "Ref": "AWS::Partition" - }, - ":", - "logs", - ":", - { - "Ref": "AWS::Region" - }, - ":", - { - "Ref": "AWS::AccountId" - }, - ":", - "log-group", - ":", "/aws/codebuild/", { "Ref": "MyProject39F7B0AE" diff --git a/packages/@aws-cdk/aws-codebuild/test/integ.project-bucket.expected.json b/packages/@aws-cdk/aws-codebuild/test/integ.project-bucket.expected.json index d2fdc48288a40..6133bf2f84897 100644 --- a/packages/@aws-cdk/aws-codebuild/test/integ.project-bucket.expected.json +++ b/packages/@aws-cdk/aws-codebuild/test/integ.project-bucket.expected.json @@ -86,9 +86,16 @@ ":", "log-group", ":", - "/aws/codebuild/", { - "Ref": "MyProject39F7B0AE" + "Fn::Join": [ + "", + [ + "/aws/codebuild/", + { + "Ref": "MyProject39F7B0AE" + } + ] + ] } ] ] @@ -97,28 +104,28 @@ "Fn::Join": [ "", [ + "arn", + ":", + { + "Ref": "AWS::Partition" + }, + ":", + "logs", + ":", + { + "Ref": "AWS::Region" + }, + ":", + { + "Ref": "AWS::AccountId" + }, + ":", + "log-group", + ":", { "Fn::Join": [ "", [ - "arn", - ":", - { - "Ref": "AWS::Partition" - }, - ":", - "logs", - ":", - { - "Ref": "AWS::Region" - }, - ":", - { - "Ref": "AWS::AccountId" - }, - ":", - "log-group", - ":", "/aws/codebuild/", { "Ref": "MyProject39F7B0AE" diff --git a/packages/@aws-cdk/aws-codebuild/test/integ.project-events.expected.json b/packages/@aws-cdk/aws-codebuild/test/integ.project-events.expected.json index 2e08546fea552..efb9d2ba2fe5e 100644 --- a/packages/@aws-cdk/aws-codebuild/test/integ.project-events.expected.json +++ b/packages/@aws-cdk/aws-codebuild/test/integ.project-events.expected.json @@ -129,9 +129,16 @@ ":", "log-group", ":", - "/aws/codebuild/", { - "Ref": "MyProject39F7B0AE" + "Fn::Join": [ + "", + [ + "/aws/codebuild/", + { + "Ref": "MyProject39F7B0AE" + } + ] + ] } ] ] @@ -140,28 +147,28 @@ "Fn::Join": [ "", [ + "arn", + ":", + { + "Ref": "AWS::Partition" + }, + ":", + "logs", + ":", + { + "Ref": "AWS::Region" + }, + ":", + { + "Ref": "AWS::AccountId" + }, + ":", + "log-group", + ":", { "Fn::Join": [ "", [ - "arn", - ":", - { - "Ref": "AWS::Partition" - }, - ":", - "logs", - ":", - { - "Ref": "AWS::Region" - }, - ":", - { - "Ref": "AWS::AccountId" - }, - ":", - "log-group", - ":", "/aws/codebuild/", { "Ref": "MyProject39F7B0AE" diff --git a/packages/@aws-cdk/aws-codebuild/test/test.codebuild.ts b/packages/@aws-cdk/aws-codebuild/test/test.codebuild.ts index c96c6f7c1ee9d..e5b09c5cf46bd 100644 --- a/packages/@aws-cdk/aws-codebuild/test/test.codebuild.ts +++ b/packages/@aws-cdk/aws-codebuild/test/test.codebuild.ts @@ -41,82 +41,89 @@ export = { "Properties": { "PolicyDocument": { "Statement": [ - { - "Action": [ - "logs:CreateLogGroup", - "logs:CreateLogStream", - "logs:PutLogEvents" - ], - "Effect": "Allow", - "Resource": [ - { - "Fn::Join": [ - "", - [ - "arn", - ":", - { - "Ref": "AWS::Partition" - }, - ":", - "logs", - ":", - { - "Ref": "AWS::Region" - }, - ":", + { + "Action": [ + "logs:CreateLogGroup", + "logs:CreateLogStream", + "logs:PutLogEvents" + ], + "Effect": "Allow", + "Resource": [ { - "Ref": "AWS::AccountId" + "Fn::Join": [ + "", + [ + "arn", + ":", + { + "Ref": "AWS::Partition" + }, + ":", + "logs", + ":", + { + "Ref": "AWS::Region" + }, + ":", + { + "Ref": "AWS::AccountId" + }, + ":", + "log-group", + ":", + { + "Fn::Join": [ + "", + [ + "/aws/codebuild/", + { + "Ref": "MyProject39F7B0AE" + } + ] + ] + } + ] + ] }, - ":", - "log-group", - ":", - "/aws/codebuild/", { - "Ref": "MyProject39F7B0AE" - } - ] - ] - }, - { - "Fn::Join": [ - "", - [ - { - "Fn::Join": [ - "", - [ - "arn", - ":", - { - "Ref": "AWS::Partition" - }, - ":", - "logs", - ":", - { - "Ref": "AWS::Region" - }, - ":", - { - "Ref": "AWS::AccountId" - }, - ":", - "log-group", - ":", - "/aws/codebuild/", - { - "Ref": "MyProject39F7B0AE" - } + "Fn::Join": [ + "", + [ + "arn", + ":", + { + "Ref": "AWS::Partition" + }, + ":", + "logs", + ":", + { + "Ref": "AWS::Region" + }, + ":", + { + "Ref": "AWS::AccountId" + }, + ":", + "log-group", + ":", + { + "Fn::Join": [ + "", + [ + "/aws/codebuild/", + { + "Ref": "MyProject39F7B0AE" + } + ] + ] + }, + ":*" + ] ] - ] - }, - ":*" - ] + } ] - } - ] - } + } ], "Version": "2012-10-17" }, @@ -238,9 +245,16 @@ export = { ":", "log-group", ":", - "/aws/codebuild/", { - "Ref": "MyProject39F7B0AE" + "Fn::Join": [ + "", + [ + "/aws/codebuild/", + { + "Ref": "MyProject39F7B0AE" + } + ] + ] } ] ] @@ -249,28 +263,28 @@ export = { "Fn::Join": [ "", [ + "arn", + ":", + { + "Ref": "AWS::Partition" + }, + ":", + "logs", + ":", + { + "Ref": "AWS::Region" + }, + ":", + { + "Ref": "AWS::AccountId" + }, + ":", + "log-group", + ":", { "Fn::Join": [ "", [ - "arn", - ":", - { - "Ref": "AWS::Partition" - }, - ":", - "logs", - ":", - { - "Ref": "AWS::Region" - }, - ":", - { - "Ref": "AWS::AccountId" - }, - ":", - "log-group", - ":", "/aws/codebuild/", { "Ref": "MyProject39F7B0AE" @@ -298,29 +312,29 @@ export = { "MyProject39F7B0AE": { "Type": "AWS::CodeBuild::Project", "Properties": { - "Source": { - "Type": "CODECOMMIT", - "Location": { - "Fn::GetAtt": [ - "MyRepoF4F48043", - "CloneUrlHttp" - ] - } - }, "Artifacts": { "Type": "NO_ARTIFACTS" }, + "Environment": { + "ComputeType": "BUILD_GENERAL1_SMALL", + "Image": "aws/codebuild/ubuntu-base:14.04", + "PrivilegedMode": false, + "Type": "LINUX_CONTAINER" + }, "ServiceRole": { "Fn::GetAtt": [ "MyProjectRole9BBE5233", "Arn" ] }, - "Environment": { - "Type": "LINUX_CONTAINER", - "PrivilegedMode": false, - "Image": "aws/codebuild/ubuntu-base:14.04", - "ComputeType": "BUILD_GENERAL1_SMALL" + "Source": { + "Location": { + "Fn::GetAtt": [ + "MyRepoF4F48043", + "CloneUrlHttp" + ] + }, + "Type": "CODECOMMIT" } } } @@ -427,9 +441,16 @@ export = { ":", "log-group", ":", - "/aws/codebuild/", { - "Ref": "MyProject39F7B0AE" + "Fn::Join": [ + "", + [ + "/aws/codebuild/", + { + "Ref": "MyProject39F7B0AE" + } + ] + ] } ] ] @@ -438,28 +459,28 @@ export = { "Fn::Join": [ "", [ + "arn", + ":", + { + "Ref": "AWS::Partition" + }, + ":", + "logs", + ":", + { + "Ref": "AWS::Region" + }, + ":", + { + "Ref": "AWS::AccountId" + }, + ":", + "log-group", + ":", { "Fn::Join": [ "", [ - "arn", - ":", - { - "Ref": "AWS::Partition" - }, - ":", - "logs", - ":", - { - "Ref": "AWS::Region" - }, - ":", - { - "Ref": "AWS::AccountId" - }, - ":", - "log-group", - ":", "/aws/codebuild/", { "Ref": "MyProject39F7B0AE" @@ -487,8 +508,22 @@ export = { "MyProject39F7B0AE": { "Type": "AWS::CodeBuild::Project", "Properties": { + "Artifacts": { + "Type": "NO_ARTIFACTS" + }, + "Environment": { + "ComputeType": "BUILD_GENERAL1_MEDIUM", + "Image": "aws/codebuild/windows-base:1.0", + "PrivilegedMode": false, + "Type": "WINDOWS_CONTAINER" + }, + "ServiceRole": { + "Fn::GetAtt": [ + "MyProjectRole9BBE5233", + "Arn" + ] + }, "Source": { - "Type": "S3", "Location": { "Fn::Join": [ "", @@ -500,22 +535,8 @@ export = { "path/to/source.zip" ] ] - } - }, - "Artifacts": { - "Type": "NO_ARTIFACTS" - }, - "ServiceRole": { - "Fn::GetAtt": [ - "MyProjectRole9BBE5233", - "Arn" - ] - }, - "Environment": { - "Type": "WINDOWS_CONTAINER", - "PrivilegedMode": false, - "Image": "aws/codebuild/windows-base:1.0", - "ComputeType": "BUILD_GENERAL1_MEDIUM" + }, + "Type": "S3" } } } From 3ad255b9de9dc3cc32810e7ef2f362404294ba65 Mon Sep 17 00:00:00 2001 From: Elad Ben-Israel Date: Mon, 17 Sep 2018 23:48:10 +0300 Subject: [PATCH 07/13] Update codebuild test --- .../test/integ.project-shell.expected.json | 51 +++++++++++-------- .../aws-codebuild/test/integ.project-shell.ts | 2 +- 2 files changed, 30 insertions(+), 23 deletions(-) diff --git a/packages/@aws-cdk/aws-codebuild/test/integ.project-shell.expected.json b/packages/@aws-cdk/aws-codebuild/test/integ.project-shell.expected.json index efb562c9c4c2d..dc13039e82083 100644 --- a/packages/@aws-cdk/aws-codebuild/test/integ.project-shell.expected.json +++ b/packages/@aws-cdk/aws-codebuild/test/integ.project-shell.expected.json @@ -2,11 +2,11 @@ "Parameters": { "BundleS3Bucket0EFC11B0": { "Type": "String", - "Description": "S3 bucket for asset \"aws-cdk-codebuild-events/Bundle\"" + "Description": "S3 bucket for asset \"aws-cdk-codebuild-project-shell/Bundle\"" }, "BundleS3VersionKey720F2199": { "Type": "String", - "Description": "S3 key for asset version \"aws-cdk-codebuild-events/Bundle\"" + "Description": "S3 key for asset version \"aws-cdk-codebuild-project-shell/Bundle\"" } }, "Resources": { @@ -145,9 +145,16 @@ ":", "log-group", ":", - "/aws/codebuild/", { - "Ref": "MyProject39F7B0AE" + "Fn::Join": [ + "", + [ + "/aws/codebuild/", + { + "Ref": "MyProject39F7B0AE" + } + ] + ] } ] ] @@ -156,28 +163,28 @@ "Fn::Join": [ "", [ + "arn", + ":", + { + "Ref": "AWS::Partition" + }, + ":", + "logs", + ":", + { + "Ref": "AWS::Region" + }, + ":", + { + "Ref": "AWS::AccountId" + }, + ":", + "log-group", + ":", { "Fn::Join": [ "", [ - "arn", - ":", - { - "Ref": "AWS::Partition" - }, - ":", - "logs", - ":", - { - "Ref": "AWS::Region" - }, - ":", - { - "Ref": "AWS::AccountId" - }, - ":", - "log-group", - ":", "/aws/codebuild/", { "Ref": "MyProject39F7B0AE" diff --git a/packages/@aws-cdk/aws-codebuild/test/integ.project-shell.ts b/packages/@aws-cdk/aws-codebuild/test/integ.project-shell.ts index 76dd45a3b7148..263b3af07101c 100644 --- a/packages/@aws-cdk/aws-codebuild/test/integ.project-shell.ts +++ b/packages/@aws-cdk/aws-codebuild/test/integ.project-shell.ts @@ -5,7 +5,7 @@ import { Project } from '../lib'; const app = new cdk.App(process.argv); -const stack = new cdk.Stack(app, 'aws-cdk-codebuild-events'); +const stack = new cdk.Stack(app, 'aws-cdk-codebuild-project-shell'); new Project(stack, 'MyProject', { buildScriptAsset: new assets.ZipDirectoryAsset(stack, 'Bundle', { path: 'script_bundle' }) From 449e9611f00f2ecb6081e4085f4fb3bcdebb4825 Mon Sep 17 00:00:00 2001 From: Elad Ben-Israel Date: Tue, 18 Sep 2018 00:01:59 +0300 Subject: [PATCH 08/13] Update codepipeline integ test --- ...g.pipeline-code-commit-build.expected.json | 47 +++++++++++-------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/packages/@aws-cdk/aws-codepipeline/test/integ.pipeline-code-commit-build.expected.json b/packages/@aws-cdk/aws-codepipeline/test/integ.pipeline-code-commit-build.expected.json index c929fc78a3225..4088ef1fa556d 100644 --- a/packages/@aws-cdk/aws-codepipeline/test/integ.pipeline-code-commit-build.expected.json +++ b/packages/@aws-cdk/aws-codepipeline/test/integ.pipeline-code-commit-build.expected.json @@ -240,9 +240,16 @@ ":", "log-group", ":", - "/aws/codebuild/", { - "Ref": "MyBuildProject30DB9D6E" + "Fn::Join": [ + "", + [ + "/aws/codebuild/", + { + "Ref": "MyBuildProject30DB9D6E" + } + ] + ] } ] ] @@ -251,28 +258,28 @@ "Fn::Join": [ "", [ + "arn", + ":", + { + "Ref": "AWS::Partition" + }, + ":", + "logs", + ":", + { + "Ref": "AWS::Region" + }, + ":", + { + "Ref": "AWS::AccountId" + }, + ":", + "log-group", + ":", { "Fn::Join": [ "", [ - "arn", - ":", - { - "Ref": "AWS::Partition" - }, - ":", - "logs", - ":", - { - "Ref": "AWS::Region" - }, - ":", - { - "Ref": "AWS::AccountId" - }, - ":", - "log-group", - ":", "/aws/codebuild/", { "Ref": "MyBuildProject30DB9D6E" From 934e0a25fff440cce4c35bcdbc8c87455bf19728 Mon Sep 17 00:00:00 2001 From: Elad Ben-Israel Date: Tue, 18 Sep 2018 00:16:39 +0300 Subject: [PATCH 09/13] update test to no-bail and codepipeline --- build.sh | 4 +- .../test/integ.pipeline-events.expected.json | 47 +++++++++++-------- 2 files changed, 29 insertions(+), 22 deletions(-) diff --git a/build.sh b/build.sh index af24eac27e587..c3f371305ad9e 100755 --- a/build.sh +++ b/build.sh @@ -19,10 +19,10 @@ trap "rm -rf $MERKLE_BUILD_CACHE" EXIT echo "=============================================================================================" echo "building..." -time lerna exec --no-bail --stream "npm run build" +time lerna run --no-bail --stream build echo "=============================================================================================" echo "testing..." -lerna run --stream test +lerna run --no-bail --stream test touch $BUILD_INDICATOR diff --git a/packages/@aws-cdk/aws-codepipeline/test/integ.pipeline-events.expected.json b/packages/@aws-cdk/aws-codepipeline/test/integ.pipeline-events.expected.json index 3bd0090bbd708..df70d70cfd542 100644 --- a/packages/@aws-cdk/aws-codepipeline/test/integ.pipeline-events.expected.json +++ b/packages/@aws-cdk/aws-codepipeline/test/integ.pipeline-events.expected.json @@ -413,9 +413,16 @@ ":", "log-group", ":", - "/aws/codebuild/", { - "Ref": "BuildProject097C5DB7" + "Fn::Join": [ + "", + [ + "/aws/codebuild/", + { + "Ref": "BuildProject097C5DB7" + } + ] + ] } ] ] @@ -424,28 +431,28 @@ "Fn::Join": [ "", [ + "arn", + ":", + { + "Ref": "AWS::Partition" + }, + ":", + "logs", + ":", + { + "Ref": "AWS::Region" + }, + ":", + { + "Ref": "AWS::AccountId" + }, + ":", + "log-group", + ":", { "Fn::Join": [ "", [ - "arn", - ":", - { - "Ref": "AWS::Partition" - }, - ":", - "logs", - ":", - { - "Ref": "AWS::Region" - }, - ":", - { - "Ref": "AWS::AccountId" - }, - ":", - "log-group", - ":", "/aws/codebuild/", { "Ref": "BuildProject097C5DB7" From a1b5755b39afd8087641af56f8fc0243292438e1 Mon Sep 17 00:00:00 2001 From: Elad Ben-Israel Date: Wed, 19 Sep 2018 14:42:42 +0300 Subject: [PATCH 10/13] CR followups * Fix typo "managedPolicieArns" => "managedPolicyArns" * Remove unneeded `.toString` * Rename `isToken(x)` to `unresolved(x)` * Rename cfn2ts `ClassDeclaration` to `AttributeTypeDeclaration` * Revert log "generated code up-to-date" from cfn2ts --- packages/@aws-cdk/aws-iam/lib/role.ts | 10 +++++----- packages/@aws-cdk/aws-iam/lib/util.ts | 6 +++--- packages/@aws-cdk/aws-s3/test/notification-dests.ts | 2 +- packages/@aws-cdk/cdk/lib/cloudformation/arn.ts | 6 +++--- packages/@aws-cdk/cdk/lib/core/tokens.ts | 4 ++-- packages/@aws-cdk/cdk/test/core/test.tokens.ts | 8 ++++---- tools/cfn2ts/lib/codegen.ts | 4 ++-- tools/cfn2ts/lib/genspec.ts | 13 +++++-------- tools/cfn2ts/lib/index.ts | 2 ++ 9 files changed, 27 insertions(+), 28 deletions(-) diff --git a/packages/@aws-cdk/aws-iam/lib/role.ts b/packages/@aws-cdk/aws-iam/lib/role.ts index 785c0ebb76c17..2260cbe11bc78 100644 --- a/packages/@aws-cdk/aws-iam/lib/role.ts +++ b/packages/@aws-cdk/aws-iam/lib/role.ts @@ -18,7 +18,7 @@ export interface RoleProps { * You can add managed policies later using `attachManagedPolicy(arn)`. * @default No managed policies. */ - managedPolicyArns?: any[]; + managedPolicyArns?: string[]; /** * The path associated with this role. For information about IAM paths, see @@ -97,20 +97,20 @@ export class Role extends Construct implements IIdentityResource, IPrincipal, ID public readonly dependencyElements: IDependable[]; private defaultPolicy?: Policy; - private readonly managedPolicieArns: string[]; + private readonly managedPolicyArns: string[]; private readonly attachedPolicies = new AttachedPolicies(); constructor(parent: Construct, name: string, props: RoleProps) { super(parent, name); this.assumeRolePolicy = createAssumeRolePolicy(props.assumedBy); - this.managedPolicieArns = props.managedPolicyArns || [ ]; + this.managedPolicyArns = props.managedPolicyArns || [ ]; validateMaxSessionDuration(props.maxSessionDurationSec); const role = new cloudformation.RoleResource(this, 'Resource', { assumeRolePolicyDocument: this.assumeRolePolicy as any, - managedPolicyArns: undefinedIfEmpty(() => this.managedPolicieArns), + managedPolicyArns: undefinedIfEmpty(() => this.managedPolicyArns), path: props.path, roleName: props.roleName, maxSessionDuration: props.maxSessionDurationSec @@ -141,7 +141,7 @@ export class Role extends Construct implements IIdentityResource, IPrincipal, ID * @param arn The ARN of the managed policy to attach. */ public attachManagedPolicy(arn: string) { - this.managedPolicieArns.push(arn); + this.managedPolicyArns.push(arn); } /** diff --git a/packages/@aws-cdk/aws-iam/lib/util.ts b/packages/@aws-cdk/aws-iam/lib/util.ts index 5577cea43d3cf..17f18a35e51a0 100644 --- a/packages/@aws-cdk/aws-iam/lib/util.ts +++ b/packages/@aws-cdk/aws-iam/lib/util.ts @@ -1,10 +1,10 @@ -import { Token } from '@aws-cdk/cdk'; +import { CloudFormationToken } from '@aws-cdk/cdk'; import { Policy } from './policy'; const MAX_POLICY_NAME_LEN = 128; -export function undefinedIfEmpty(f: () => T[]): Token { - return new Token(() => { +export function undefinedIfEmpty(f: () => T[]): CloudFormationToken { + return new CloudFormationToken(() => { const array = f(); return (array && array.length > 0) ? array : undefined; }); diff --git a/packages/@aws-cdk/aws-s3/test/notification-dests.ts b/packages/@aws-cdk/aws-s3/test/notification-dests.ts index 02cc6836b7074..7899fa6a983be 100644 --- a/packages/@aws-cdk/aws-s3/test/notification-dests.ts +++ b/packages/@aws-cdk/aws-s3/test/notification-dests.ts @@ -24,7 +24,7 @@ export class Topic extends cdk.Construct implements s3notifications.IBucketNotif } }); - this.topicArn = topicArn.toString(); + this.topicArn = topicArn; } public asBucketNotificationDestination(bucketArn: string, bucketId: string): s3notifications.BucketNotificationDestinationProps { diff --git a/packages/@aws-cdk/cdk/lib/cloudformation/arn.ts b/packages/@aws-cdk/cdk/lib/cloudformation/arn.ts index 998223eecb1e9..a4d3079bef400 100644 --- a/packages/@aws-cdk/cdk/lib/cloudformation/arn.ts +++ b/packages/@aws-cdk/cdk/lib/cloudformation/arn.ts @@ -1,6 +1,6 @@ import { AwsAccountId, AwsPartition, AwsRegion, FnConcat, Token } from '..'; import { FnSelect, FnSplit } from '../cloudformation/fn'; -import { isToken } from '../core/tokens'; +import { unresolved } from '../core/tokens'; import { CloudFormationToken } from './cloudformation-token'; /** @@ -86,8 +86,8 @@ export class ArnUtils { * components of the ARN. */ public static parse(arn: string, sepIfToken: string = '/', hasName: boolean = true): ArnComponents { - if (isToken(arn)) { - return this.parseToken(new CloudFormationToken(arn), sepIfToken, hasName); + if (unresolved(arn)) { + return ArnUtils.parseToken(new CloudFormationToken(arn), sepIfToken, hasName); } const components = arn.split(':') as Array; diff --git a/packages/@aws-cdk/cdk/lib/core/tokens.ts b/packages/@aws-cdk/cdk/lib/core/tokens.ts index 2f017ac846f20..16eda99249148 100644 --- a/packages/@aws-cdk/cdk/lib/core/tokens.ts +++ b/packages/@aws-cdk/cdk/lib/core/tokens.ts @@ -106,7 +106,7 @@ export class Token { * that includes token markers). * @param obj The object to test. */ -export function isToken(obj: any): obj is Token { +export function unresolved(obj: any): obj is Token { if (typeof(obj) === 'string') { return TOKEN_STRING_MAP.createTokenString(obj).test(); } else { @@ -173,7 +173,7 @@ export function resolve(obj: any, prefix?: string[]): any { // tokens - invoke 'resolve' and continue to resolve recursively // - if (isToken(obj)) { + if (unresolved(obj)) { const value = obj[RESOLVE_METHOD](); return resolve(value, path); } diff --git a/packages/@aws-cdk/cdk/test/core/test.tokens.ts b/packages/@aws-cdk/cdk/test/core/test.tokens.ts index 621539538895b..d00841228c6bb 100644 --- a/packages/@aws-cdk/cdk/test/core/test.tokens.ts +++ b/packages/@aws-cdk/cdk/test/core/test.tokens.ts @@ -1,5 +1,5 @@ import { Test } from 'nodeunit'; -import { CloudFormationToken, isToken, resolve, Token } from '../../lib'; +import { CloudFormationToken, unresolved, resolve, Token } from '../../lib'; import { evaluateCFN } from '../cloudformation/evaluate-cfn'; export = { @@ -123,9 +123,9 @@ export = { }, 'isToken(obj) can be used to determine if an object is a token'(test: Test) { - test.ok(isToken({ resolve: () => 123 })); - test.ok(isToken({ a: 1, b: 2, resolve: () => 'hello' })); - test.ok(!isToken({ a: 1, b: 2, resolve: 3 })); + test.ok(unresolved({ resolve: () => 123 })); + test.ok(unresolved({ a: 1, b: 2, resolve: () => 'hello' })); + test.ok(!unresolved({ a: 1, b: 2, resolve: 3 })); test.done(); }, diff --git a/tools/cfn2ts/lib/codegen.ts b/tools/cfn2ts/lib/codegen.ts index 81cf89029b976..52c9a6e88f40c 100644 --- a/tools/cfn2ts/lib/codegen.ts +++ b/tools/cfn2ts/lib/codegen.ts @@ -220,7 +220,7 @@ export default class CodeGenerator { // Attributes // - const attributeTypes = new Array(); + const attributeTypes = new Array(); const attributes = new Array(); if (spec.Attributes) { @@ -480,7 +480,7 @@ export default class CodeGenerator { /** * Attribute types are classes that represent resource attributes (e.g. QueueArnAttribute). */ - private emitAttributeType(attr: genspec.ClassDeclaration) { + private emitAttributeType(attr: genspec.AttributeTypeDeclaration) { if (!attr.baseClassName) { return; // primitive, no attribute type generated } diff --git a/tools/cfn2ts/lib/genspec.ts b/tools/cfn2ts/lib/genspec.ts index 7d34a564b2233..3e03018b39b65 100644 --- a/tools/cfn2ts/lib/genspec.ts +++ b/tools/cfn2ts/lib/genspec.ts @@ -104,7 +104,7 @@ export class CodeName { /** * Class declaration */ -export class ClassDeclaration { +export class AttributeTypeDeclaration { constructor( readonly typeName: CodeName, readonly baseClassName?: CodeName, @@ -118,7 +118,6 @@ export class ClassDeclaration { } export const TAG_NAME = new CodeName('', CORE_NAMESPACE, 'Tag'); -export const ARN_NAME = new CodeName('', CORE_NAMESPACE, 'Arn'); export const TOKEN_NAME = new CodeName('', CORE_NAMESPACE, 'CloudFormationToken'); /** @@ -127,7 +126,7 @@ export const TOKEN_NAME = new CodeName('', CORE_NAMESPACE, 'CloudFormationToken' export class Attribute { constructor( readonly propertyName: string, - readonly attributeType: ClassDeclaration, + readonly attributeType: AttributeTypeDeclaration, readonly constructorArguments: string) { } } @@ -194,13 +193,11 @@ export function attributeDefinition(resourceName: CodeName, attributeName: strin let attrType; if ('PrimitiveType' in spec && spec.PrimitiveType === 'String') { - attrType = new ClassDeclaration(CodeName.forPrimitive('string')); + attrType = new AttributeTypeDeclaration(CodeName.forPrimitive('string')); } else { // Not in a namespace, base the name on the descriptive name const typeName = new CodeName(resourceName.packageName, '', descriptiveName); // "BucketArn" - const baseClass = attributeName.endsWith('Arn') ? ARN_NAME : TOKEN_NAME; - - attrType = new ClassDeclaration(typeName, baseClass, undefined); + attrType = new AttributeTypeDeclaration(typeName, TOKEN_NAME, undefined); } const constructorArguments = `this.getAtt('${attributeName}')`; @@ -215,7 +212,7 @@ export function refAttributeDefinition(resourceName: CodeName, refKind: string): const constructorArguments = 'this.ref'; - const refType = new ClassDeclaration(CodeName.forPrimitive('string')); + const refType = new AttributeTypeDeclaration(CodeName.forPrimitive('string')); return new Attribute(propertyName, refType, constructorArguments); } diff --git a/tools/cfn2ts/lib/index.ts b/tools/cfn2ts/lib/index.ts index 435e60308b0e6..12bfa2e9b8107 100644 --- a/tools/cfn2ts/lib/index.ts +++ b/tools/cfn2ts/lib/index.ts @@ -17,6 +17,8 @@ export default async function(scope: string, outPath: string, force: boolean) { const generator = new CodeGenerator(name, spec); if (!force && await generator.upToDate(outPath)) { + // tslint:disable-next-line:no-console + console.log('Generated code already up-to-date: %s', colors.green(path.join(outPath, generator.outputFile))); return; } generator.emitCode(); From 51b2924a0671d548952e37e1c18dcfe1f2e5d005 Mon Sep 17 00:00:00 2001 From: Elad Ben-Israel Date: Wed, 19 Sep 2018 14:59:16 +0300 Subject: [PATCH 11/13] Fix build break --- packages/@aws-cdk/cdk/test/core/test.tokens.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/@aws-cdk/cdk/test/core/test.tokens.ts b/packages/@aws-cdk/cdk/test/core/test.tokens.ts index d00841228c6bb..2ef63b7a9bac2 100644 --- a/packages/@aws-cdk/cdk/test/core/test.tokens.ts +++ b/packages/@aws-cdk/cdk/test/core/test.tokens.ts @@ -1,5 +1,5 @@ import { Test } from 'nodeunit'; -import { CloudFormationToken, unresolved, resolve, Token } from '../../lib'; +import { CloudFormationToken, resolve, Token, unresolved } from '../../lib'; import { evaluateCFN } from '../cloudformation/evaluate-cfn'; export = { From d84b8716d01450f4cd223b79a9e0cff314532f6f Mon Sep 17 00:00:00 2001 From: Elad Ben-Israel Date: Wed, 19 Sep 2018 15:24:25 +0300 Subject: [PATCH 12/13] More followups * Restore custom resource example * Change `resource.getAtt` to return a token --- .../custom-resource/index.ts | 104 ++++++++++++++++++ .../custom-resource/provider.py | 26 +++++ packages/@aws-cdk/aws-ec2/lib/vpc.ts | 2 +- .../notifications-resource-handler.ts | 2 +- .../cdk/lib/cloudformation/resource.ts | 4 +- 5 files changed, 134 insertions(+), 4 deletions(-) create mode 100644 examples/cdk-examples-typescript/custom-resource/index.ts create mode 100644 examples/cdk-examples-typescript/custom-resource/provider.py diff --git a/examples/cdk-examples-typescript/custom-resource/index.ts b/examples/cdk-examples-typescript/custom-resource/index.ts new file mode 100644 index 0000000000000..0b0db906ecf3c --- /dev/null +++ b/examples/cdk-examples-typescript/custom-resource/index.ts @@ -0,0 +1,104 @@ +import { CustomResource } from '@aws-cdk/aws-cloudformation'; +import lambda = require('@aws-cdk/aws-lambda'); +import { cloudformation as s3 } from '@aws-cdk/aws-s3'; +import cdk = require('@aws-cdk/cdk'); +import fs = require('fs'); + +interface DemoResourceProps { + /** + * Message to echo + */ + message: string; + + /** + * Set this to true to fail the CREATE invocation + */ + failCreate?: boolean; +} + +class DemoResource extends cdk.Construct implements cdk.IDependable { + public readonly dependencyElements: cdk.IDependable[]; + public readonly response: string; + + constructor(parent: cdk.Construct, name: string, props: DemoResourceProps) { + super(parent, name); + + const resource = new CustomResource(this, 'Resource', { + lambdaProvider: new lambda.SingletonFunction(this, 'Singleton', { + uuid: 'f7d4f730-4ee1-11e8-9c2d-fa7ae01bbebc', + // This makes the demo only work as top-level TypeScript program, but that's fine for now + code: lambda.Code.inline(fs.readFileSync('provider.py', { encoding: 'utf-8' })), + handler: 'index.main', + timeout: 300, + runtime: lambda.Runtime.Python27, + }), + properties: props + }); + + this.response = resource.getAtt('Response').toString(); + this.dependencyElements = [resource]; + } +} + +/** + * A stack that only sets up the CustomResource and shows how to get an attribute from it + */ +class SucceedingStack extends cdk.Stack { + constructor(parent: cdk.App, name: string, props?: cdk.StackProps) { + super(parent, name, props); + + const resource = new DemoResource(this, 'DemoResource', { + message: 'CustomResource says hello', + }); + + // Publish the custom resource output + new cdk.Output(this, 'ResponseMessage', { + description: 'The message that came back from the Custom Resource', + value: resource.response + }); + } +} + +/** + * A stack that sets up a failing CustomResource creation + */ +class FailCreationStack extends cdk.Stack { + constructor(parent: cdk.App, name: string, props?: cdk.StackProps) { + super(parent, name, props); + + new DemoResource(this, 'DemoResource', { + message: 'CustomResource is silent', + failCreate: true + }); + } +} + +/** + * A stack that sets up the CustomResource and fails afterwards, to check that cleanup gets + * done properly. + */ +class FailAfterCreatingStack extends cdk.Stack { + constructor(parent: cdk.App, name: string, props?: cdk.StackProps) { + super(parent, name, props); + + const resource = new DemoResource(this, 'DemoResource', { + message: 'CustomResource says hello', + }); + + // Bucket with an invalid name will fail the deployment and cause a rollback + const bucket = new s3.BucketResource(this, 'FailingBucket', { + bucketName: 'hello!@#$^' + }); + + // Make sure the rollback gets triggered only after the custom resource has been fully created. + bucket.addDependency(resource); + } +} + +const app = new cdk.App(process.argv); + +new SucceedingStack(app, 'SucceedingStack'); +new FailCreationStack(app, 'FailCreationStack'); +new FailAfterCreatingStack(app, 'FailAfterCreatingStack'); + +process.stdout.write(app.run()); \ No newline at end of file diff --git a/examples/cdk-examples-typescript/custom-resource/provider.py b/examples/cdk-examples-typescript/custom-resource/provider.py new file mode 100644 index 0000000000000..d2294771d0083 --- /dev/null +++ b/examples/cdk-examples-typescript/custom-resource/provider.py @@ -0,0 +1,26 @@ +def main(event, context): + import logging as log + import cfnresponse + log.getLogger().setLevel(log.INFO) + + # This needs to change if there are to be multiple resources in the same stack + physical_id = 'TheOnlyCustomResource' + + try: + log.info('Input event: %s', event) + + # Check if this is a Create and we're failing Creates + if event['RequestType'] == 'Create' and event['ResourceProperties'].get('FailCreate', False): + raise RuntimeError('Create failure requested') + + # Do the thing + message = event['ResourceProperties']['Message'] + attributes = { + 'Response': 'You said "%s"' % message + } + + cfnresponse.send(event, context, cfnresponse.SUCCESS, attributes, physical_id) + except Exception as e: + log.exception(e) + # cfnresponse's error message is always "see CloudWatch" + cfnresponse.send(event, context, cfnresponse.FAILED, {}, physical_id) \ No newline at end of file diff --git a/packages/@aws-cdk/aws-ec2/lib/vpc.ts b/packages/@aws-cdk/aws-ec2/lib/vpc.ts index 5f0bf868ddb2a..234c76552b5a5 100644 --- a/packages/@aws-cdk/aws-ec2/lib/vpc.ts +++ b/packages/@aws-cdk/aws-ec2/lib/vpc.ts @@ -344,7 +344,7 @@ export class VpcNetwork extends VpcNetworkRef implements cdk.ITaggable { * @returns The IPv4 CidrBlock as returned by the VPC */ public get cidr(): string { - return this.resource.getAtt("CidrBlock"); + return this.resource.getAtt("CidrBlock").toString(); } /** diff --git a/packages/@aws-cdk/aws-s3/lib/notifications-resource/notifications-resource-handler.ts b/packages/@aws-cdk/aws-s3/lib/notifications-resource/notifications-resource-handler.ts index e42b6d06d16a4..91c02e33fb1a0 100644 --- a/packages/@aws-cdk/aws-s3/lib/notifications-resource/notifications-resource-handler.ts +++ b/packages/@aws-cdk/aws-s3/lib/notifications-resource/notifications-resource-handler.ts @@ -77,7 +77,7 @@ export class NotificationsResourceHandler extends cdk.Construct { } }); - this.functionArn = resource.getAtt('Arn'); + this.functionArn = resource.getAtt('Arn').toString(); } } diff --git a/packages/@aws-cdk/cdk/lib/cloudformation/resource.ts b/packages/@aws-cdk/cdk/lib/cloudformation/resource.ts index 65266bf9fe951..1b050445116b7 100644 --- a/packages/@aws-cdk/cdk/lib/cloudformation/resource.ts +++ b/packages/@aws-cdk/cdk/lib/cloudformation/resource.ts @@ -81,8 +81,8 @@ export class Resource extends Referenceable { * in case there is no generated attribute. * @param attributeName The name of the attribute. */ - public getAtt(attributeName: string): string { - return new CloudFormationToken({ 'Fn::GetAtt': [this.logicalId, attributeName] }, `${this.logicalId}.${attributeName}`).toString(); + public getAtt(attributeName: string) { + return new CloudFormationToken({ 'Fn::GetAtt': [this.logicalId, attributeName] }, `${this.logicalId}.${attributeName}`); } /** From 3817d21fa7fe2373281a6f7d801f670fa69ba326 Mon Sep 17 00:00:00 2001 From: Elad Ben-Israel Date: Wed, 19 Sep 2018 15:32:10 +0300 Subject: [PATCH 13/13] Fix build break and announce errors --- build.sh | 9 +++++++-- packages/@aws-cdk/aws-quickstarts/lib/rdgw.ts | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/build.sh b/build.sh index c3f371305ad9e..28997e424f743 100755 --- a/build.sh +++ b/build.sh @@ -5,6 +5,11 @@ if [ ! -d node_modules ]; then /bin/bash ./install.sh fi +fail() { + echo "❌ Last command failed. Scroll up to see errors in log." + exit 1 +} + /bin/bash ./git-secrets-scan.sh BUILD_INDICATOR=".BUILD_COMPLETED" @@ -19,10 +24,10 @@ trap "rm -rf $MERKLE_BUILD_CACHE" EXIT echo "=============================================================================================" echo "building..." -time lerna run --no-bail --stream build +time lerna run --no-bail --stream build || fail echo "=============================================================================================" echo "testing..." -lerna run --no-bail --stream test +lerna run --no-bail --stream test || fail touch $BUILD_INDICATOR diff --git a/packages/@aws-cdk/aws-quickstarts/lib/rdgw.ts b/packages/@aws-cdk/aws-quickstarts/lib/rdgw.ts index d7bca3737dbe1..673cfce7f63a9 100644 --- a/packages/@aws-cdk/aws-quickstarts/lib/rdgw.ts +++ b/packages/@aws-cdk/aws-quickstarts/lib/rdgw.ts @@ -48,7 +48,7 @@ export class RemoteDesktopGateway extends cdk.Construct implements ec2.IConnecta }); const securityGroup = ec2.SecurityGroupRef.import(this, 'SecurityGroup', { - securityGroupId: nestedStack.getAtt('Outputs.RemoteDesktopGatewaySGID') + securityGroupId: nestedStack.getAtt('Outputs.RemoteDesktopGatewaySGID').toString() }); const defaultPortRange = new ec2.TcpPort(RemoteDesktopGateway.PORT);