Skip to content

Commit

Permalink
chore: remove usage of deprecated symbols (aws#13500)
Browse files Browse the repository at this point in the history
Across the CDK repo, remove the usage of deprecated symbols.

These are going to be removed in CDKv2, and these changes make
the codebases on the two branches more aligned.

However, this does not remove *all* usages of deprecated symbols,
but only the changes that are backwards compatible.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
Niranjan Jayakar authored and hollanddd committed Aug 26, 2021
1 parent c273240 commit 77b573b
Show file tree
Hide file tree
Showing 78 changed files with 189 additions and 140 deletions.
5 changes: 5 additions & 0 deletions allowed-breaking-changes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,8 @@ incompatible-argument:@aws-cdk/aws-ecs.TaskDefinition.addVolume
# We made properties optional and it's really fine but our differ doesn't think so.
weakened:@aws-cdk/cloud-assembly-schema.DockerImageSource
weakened:@aws-cdk/cloud-assembly-schema.FileSource

# Changed required deprecated props from required -> optional.
# These are fine, since they shouldn't be widely used.
weakened:@aws-cdk/core.FileAssetLocation
weakened:@aws-cdk/aws-events.RuleTargetConfig
12 changes: 6 additions & 6 deletions packages/@aws-cdk/assets/test/test.staging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export = {
// WHEN
const staging = new Staging(stack, 's1', { sourcePath });

test.deepEqual(staging.sourceHash, '2f37f937c51e2c191af66acf9b09f548926008ec68c575bd2ee54b6e997c0e00');
test.deepEqual(staging.assetHash, '2f37f937c51e2c191af66acf9b09f548926008ec68c575bd2ee54b6e997c0e00');
test.deepEqual(staging.sourcePath, sourcePath);
test.deepEqual(staging.relativeStagedPath(stack), 'asset.2f37f937c51e2c191af66acf9b09f548926008ec68c575bd2ee54b6e997c0e00');
test.done();
Expand All @@ -29,9 +29,9 @@ export = {
// WHEN
const staging = new Staging(stack, 's1', { sourcePath });

test.deepEqual(staging.sourceHash, '2f37f937c51e2c191af66acf9b09f548926008ec68c575bd2ee54b6e997c0e00');
test.deepEqual(staging.assetHash, '2f37f937c51e2c191af66acf9b09f548926008ec68c575bd2ee54b6e997c0e00');
test.deepEqual(staging.sourcePath, sourcePath);
test.deepEqual(staging.stagedPath, sourcePath);
test.deepEqual(staging.absoluteStagedPath, sourcePath);
test.done();
},

Expand Down Expand Up @@ -70,9 +70,9 @@ export = {
const withExtra = new Staging(stack, 'withExtra', { sourcePath: directory, extraHash: 'boom' });

// THEN
test.notEqual(withoutExtra.sourceHash, withExtra.sourceHash);
test.deepEqual(withoutExtra.sourceHash, '2f37f937c51e2c191af66acf9b09f548926008ec68c575bd2ee54b6e997c0e00');
test.deepEqual(withExtra.sourceHash, 'c95c915a5722bb9019e2c725d11868e5a619b55f36172f76bcbcaa8bb2d10c5f');
test.notEqual(withoutExtra.assetHash, withExtra.assetHash);
test.deepEqual(withoutExtra.assetHash, '2f37f937c51e2c191af66acf9b09f548926008ec68c575bd2ee54b6e997c0e00');
test.deepEqual(withExtra.assetHash, 'c95c915a5722bb9019e2c725d11868e5a619b55f36172f76bcbcaa8bb2d10c5f');
test.done();
},
};
32 changes: 26 additions & 6 deletions packages/@aws-cdk/aws-apigateway/lib/restapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,10 @@ export abstract class RestApiBase extends Resource implements IRestApi {
ignore(deployment);
}

protected configureCloudWatchRole(apiResource: CfnRestApi) {
/**
* @internal
*/
protected _configureCloudWatchRole(apiResource: CfnRestApi) {
const role = new iam.Role(this, 'CloudWatchRole', {
assumedBy: new iam.ServicePrincipal('apigateway.amazonaws.com'),
managedPolicies: [iam.ManagedPolicy.fromAwsManagedPolicyName('service-role/AmazonAPIGatewayPushToCloudWatchLogs')],
Expand All @@ -503,7 +506,24 @@ export abstract class RestApiBase extends Resource implements IRestApi {
resource.node.addDependency(apiResource);
}

protected configureDeployment(props: RestApiOptions) {
/**
* @deprecated This method will be made internal. No replacement
*/
protected configureCloudWatchRole(apiResource: CfnRestApi) {
this._configureCloudWatchRole(apiResource);
}

/**
* @deprecated This method will be made internal. No replacement
*/
protected configureDeployment(props: RestApiBaseProps) {
this._configureDeployment(props);
}

/**
* @internal
*/
protected _configureDeployment(props: RestApiBaseProps) {
const deploy = props.deploy ?? true;
if (deploy) {

Expand Down Expand Up @@ -603,14 +623,14 @@ export class SpecRestApi extends RestApiBase {
this.restApiRootResourceId = resource.attrRootResourceId;
this.root = new RootResource(this, {}, this.restApiRootResourceId);

this.configureDeployment(props);
this._configureDeployment(props);
if (props.domainName) {
this.addDomainName('CustomDomain', props.domainName);
}

const cloudWatchRole = props.cloudWatchRole ?? true;
if (cloudWatchRole) {
this.configureCloudWatchRole(resource);
this._configureCloudWatchRole(resource);
}
}
}
Expand Down Expand Up @@ -708,10 +728,10 @@ export class RestApi extends RestApiBase {

const cloudWatchRole = props.cloudWatchRole ?? true;
if (cloudWatchRole) {
this.configureCloudWatchRole(resource);
this._configureCloudWatchRole(resource);
}

this.configureDeployment(props);
this._configureDeployment(props);
if (props.domainName) {
this.addDomainName('CustomDomain', props.domainName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class MultiStack extends cdk.Stack {
const hello = new apigw.LambdaIntegration(new lambda.Function(this, 'Hello', {
runtime: lambda.Runtime.NODEJS_10_X,
handler: 'index.handler',
code: lambda.Code.inline(`exports.handler = ${helloCode}`),
code: lambda.Code.fromInline(`exports.handler = ${helloCode}`),
}));

const api = new apigw.RestApi(this, 'hello-api');
Expand Down
8 changes: 4 additions & 4 deletions packages/@aws-cdk/aws-apigatewayv2/lib/http/vpc-link.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as ec2 from '@aws-cdk/aws-ec2';
import { IResource, Lazy, Resource } from '@aws-cdk/core';
import { IResource, Lazy, Names, Resource } from '@aws-cdk/core';
import { Construct } from 'constructs';
import { CfnVpcLink } from '../apigatewayv2.generated';

Expand Down Expand Up @@ -92,9 +92,9 @@ export class VpcLink extends Resource implements IVpcLink {
this.vpc = props.vpc;

const cfnResource = new CfnVpcLink(this, 'Resource', {
name: props.vpcLinkName || Lazy.stringValue({ produce: () => this.node.uniqueId }),
subnetIds: Lazy.listValue({ produce: () => this.renderSubnets() }),
securityGroupIds: Lazy.listValue({ produce: () => this.renderSecurityGroups() }),
name: props.vpcLinkName || Lazy.string({ produce: () => Names.uniqueId(this) }),
subnetIds: Lazy.list({ produce: () => this.renderSubnets() }),
securityGroupIds: Lazy.list({ produce: () => this.renderSecurityGroups() }),
});

this.vpcLinkId = cfnResource.ref;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export class ScalableTarget extends Resource implements IScalableTarget {
* Add a policy statement to the role's policy
*/
public addToRolePolicy(statement: iam.PolicyStatement) {
this.role.addToPolicy(statement);
this.role.addToPrincipalPolicy(statement);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions packages/@aws-cdk/aws-appmesh/lib/virtual-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@ export class VirtualNode extends VirtualNodeBase {
virtualNodeName: this.physicalName,
meshName: this.mesh.meshName,
spec: {
backends: cdk.Lazy.anyValue({ produce: () => this.backends }, { omitEmptyArray: true }),
listeners: cdk.Lazy.anyValue({ produce: () => this.listeners.map(listener => listener.listener) }, { omitEmptyArray: true }),
backends: cdk.Lazy.any({ produce: () => this.backends }, { omitEmptyArray: true }),
listeners: cdk.Lazy.any({ produce: () => this.listeners.map(listener => listener.listener) }, { omitEmptyArray: true }),
backendDefaults: props.backendDefaults !== undefined
? {
clientPolicy: props.backendDefaults?.clientPolicy?.bind(this).clientPolicy,
Expand Down
7 changes: 4 additions & 3 deletions packages/@aws-cdk/aws-autoscaling/lib/auto-scaling-group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1097,7 +1097,7 @@ export class AutoScalingGroup extends AutoScalingGroupBase implements
* Adds a statement to the IAM role assumed by instances of this fleet.
*/
public addToRolePolicy(statement: iam.PolicyStatement) {
this.role.addToPolicy(statement);
this.role.addToPrincipalPolicy(statement);
}

/**
Expand Down Expand Up @@ -1225,7 +1225,7 @@ export class AutoScalingGroup extends AutoScalingGroupBase implements
...this.autoScalingGroup.cfnOptions.creationPolicy,
resourceSignal: {
count: props.resourceSignalCount,
timeout: props.resourceSignalTimeout && props.resourceSignalTimeout.toISOString(),
timeout: props.resourceSignalTimeout && props.resourceSignalTimeout.toIsoString(),
},
};
}
Expand Down Expand Up @@ -1327,6 +1327,7 @@ export enum ScalingEvent {

/**
* Additional settings when a rolling update is selected
* @deprecated use `UpdatePolicy.rollingUpdate()`
*/
export interface RollingUpdateConfiguration {
/**
Expand Down Expand Up @@ -1516,7 +1517,7 @@ function renderRollingUpdateConfig(config: RollingUpdateConfiguration = {}): Cfn
minInstancesInService: config.minInstancesInService,
minSuccessfulInstancesPercent: validatePercentage(config.minSuccessfulInstancesPercent),
waitOnResourceSignals,
pauseTime: pauseTime && pauseTime.toISOString(),
pauseTime: pauseTime && pauseTime.toIsoString(),
suspendProcesses: config.suspendProcesses ?? DEFAULT_SUSPEND_PROCESSES,
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ nodeunitShim({

class FakeNotificationTarget implements autoscaling.ILifecycleHookTarget {
public bind(_scope: constructs.Construct, lifecycleHook: autoscaling.ILifecycleHook): autoscaling.LifecycleHookTargetConfig {
lifecycleHook.role.addToPolicy(new iam.PolicyStatement({
lifecycleHook.role.addToPrincipalPolicy(new iam.PolicyStatement({
actions: ['action:Work'],
resources: ['*'],
}));
Expand Down
5 changes: 1 addition & 4 deletions packages/@aws-cdk/aws-batch/test/compute-environment.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,7 @@ describe('Batch Compute Evironment', () => {
},
desiredvCpus: 1,
ec2KeyPair: 'my-key-pair',
image: new ecs.EcsOptimizedAmi({
generation: ec2.AmazonLinuxGeneration.AMAZON_LINUX_2,
hardwareType: ecs.AmiHardwareType.STANDARD,
}),
image: ecs.EcsOptimizedImage.amazonLinux2(ecs.AmiHardwareType.STANDARD),
instanceRole: new iam.CfnInstanceProfile(stack, 'Instance-Profile', {
roles: [new iam.Role(stack, 'Ecs-Instance-Role', {
assumedBy: new iam.ServicePrincipal('ec2.amazonaws.com'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class MyNestedStack extends cfn.NestedStack {
if (props.subscriber) {
new lambda.Function(this, 'fn', {
runtime: lambda.Runtime.NODEJS_10_X,
code: lambda.Code.inline('console.error("hi")'),
code: lambda.Code.fromInline('console.error("hi")'),
handler: 'index.handler',
environment: {
TOPIC_ARN: props.siblingTopic?.topicArn ?? '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class NestedStack extends cfn.NestedStack {
super(scope, id);

new lambda.Function(this, 'Handler', {
code: lambda.Code.asset(path.join(__dirname, 'asset-directory-fixture')),
code: lambda.Code.fromAsset(path.join(__dirname, 'asset-directory-fixture')),
runtime: lambda.Runtime.NODEJS_10_X,
handler: 'index.handler',
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -811,7 +811,7 @@ export = {
const nested = new NestedStack(parent, 'nested-stack');

// WHEN
const location = nested.addDockerImageAsset({
const location = nested.synthesizer.addDockerImageAsset({
directoryName: 'my-image',
dockerBuildArgs: { key: 'value', boom: 'bam' },
dockerBuildTarget: 'buildTarget',
Expand Down
1 change: 1 addition & 0 deletions packages/@aws-cdk/aws-cloudfront/lib/web-distribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export enum FailoverStatusCode {
* "cloudfront.net" domain. To use this feature you must provide the list of
* additional domains, and the ACM Certificate that CloudFront should use for
* these additional domains.
* @deprecated see {@link CloudFrontWebDistributionProps#viewerCertificate} with {@link ViewerCertificate#acmCertificate}
*/
export interface AliasConfiguration {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ nodeunitShim({
const sourceBucket = new s3.Bucket(stack, 'Bucket');

const lambdaFunction = new lambda.Function(stack, 'Lambda', {
code: lambda.Code.inline('foo'),
code: lambda.Code.fromInline('foo'),
handler: 'index.handler',
runtime: lambda.Runtime.NODEJS_10_X,
});
Expand Down Expand Up @@ -580,7 +580,7 @@ nodeunitShim({
const sourceBucket = new s3.Bucket(stack, 'Bucket');

const lambdaFunction = new lambda.Function(stack, 'Lambda', {
code: lambda.Code.inline('foo'),
code: lambda.Code.fromInline('foo'),
handler: 'index.handler',
runtime: lambda.Runtime.NODEJS_10_X,
});
Expand Down Expand Up @@ -618,7 +618,7 @@ nodeunitShim({
const sourceBucket = new s3.Bucket(stack, 'Bucket');

const lambdaFunction = new lambda.Function(stack, 'Lambda', {
code: lambda.Code.inline('foo'),
code: lambda.Code.fromInline('foo'),
handler: 'index.handler',
runtime: lambda.Runtime.NODEJS_10_X,
environment: {
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-cloudtrail/lib/cloudtrail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ export class Trail extends Resource {

logsRole = new iam.Role(this, 'LogsRole', { assumedBy: cloudTrailPrincipal });

logsRole.addToPolicy(new iam.PolicyStatement({
logsRole.addToPrincipalPolicy(new iam.PolicyStatement({
actions: ['logs:PutLogEvents', 'logs:CreateLogStream'],
resources: [this.logGroup.logGroupArn],
}));
Expand Down
10 changes: 10 additions & 0 deletions packages/@aws-cdk/aws-cloudwatch/lib/metric.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ export class Metric implements IMetric {
};
}

/** @deprecated use toMetricConfig() */
public toAlarmConfig(): MetricAlarmConfig {
const metricConfig = this.toMetricConfig();
if (metricConfig.metricStat === undefined) {
Expand All @@ -324,6 +325,9 @@ export class Metric implements IMetric {
};
}

/**
* @deprecated use toMetricConfig()
*/
public toGraphConfig(): MetricGraphConfig {
const metricConfig = this.toMetricConfig();
if (metricConfig.metricStat === undefined) {
Expand Down Expand Up @@ -479,10 +483,16 @@ export class MathExpression implements IMetric {
});
}

/**
* @deprecated use toMetricConfig()
*/
public toAlarmConfig(): MetricAlarmConfig {
throw new Error('Using a math expression is not supported here. Pass a \'Metric\' object instead');
}

/**
* @deprecated use toMetricConfig()
*/
public toGraphConfig(): MetricGraphConfig {
throw new Error('Using a math expression is not supported here. Pass a \'Metric\' object instead');
}
Expand Down
1 change: 1 addition & 0 deletions packages/@aws-cdk/aws-cloudwatch/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
"duration-prop-type:@aws-cdk/aws-cloudwatch.MetricAlarmConfig.period",
"duration-prop-type:@aws-cdk/aws-cloudwatch.MetricGraphConfig.period",
"duration-prop-type:@aws-cdk/aws-cloudwatch.MetricRenderingProperties.period",
"no-unused-type:@aws-cdk/aws-cloudwatch.Statistic",
"props-default-doc:@aws-cdk/aws-cloudwatch.MetricAlarmConfig.dimensions",
"props-default-doc:@aws-cdk/aws-cloudwatch.MetricAlarmConfig.extendedStatistic",
"props-default-doc:@aws-cdk/aws-cloudwatch.MetricAlarmConfig.statistic",
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-cloudwatch/test/test.metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export = {
// GIVEN
const stack = new cdk.Stack();
const role = new iam.Role(stack, 'SomeRole', {
assumedBy: new iam.Anyone(),
assumedBy: new iam.AnyPrincipal(),
});

// WHEN
Expand Down
4 changes: 2 additions & 2 deletions packages/@aws-cdk/aws-codebuild/lib/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ abstract class ProjectBase extends Resource implements IProject {
*/
public addToRolePolicy(statement: iam.PolicyStatement) {
if (this.role) {
this.role.addToPolicy(statement);
this.role.addToPrincipalPolicy(statement);
}
}

Expand Down Expand Up @@ -1229,7 +1229,7 @@ export class Project extends ProjectBase {
return;
}

this.role.addToPolicy(new iam.PolicyStatement({
this.role.addToPrincipalPolicy(new iam.PolicyStatement({
resources: [`arn:${Aws.PARTITION}:ec2:${Aws.REGION}:${Aws.ACCOUNT_ID}:network-interface/*`],
actions: ['ec2:CreateNetworkInterfacePermission'],
conditions: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class TestStack extends cdk.Stack {
constructor(scope: cdk.App, id: string) {
super(scope, id);

const secrets = secretsmanager.Secret.fromSecretArn(this, 'MySecrets',
const secrets = secretsmanager.Secret.fromSecretCompleteArn(this, 'MySecrets',
`arn:aws:secretsmanager:${this.region}:${this.account}:secret:my-secrets-123456`);

new codebuild.Project(this, 'MyProject', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
"HandlerServiceRoleFCDC14AE"
]
},
"HandlerVersion1F237F6D0": {
"HandlerCurrentVersion93FB80BFa1c6e812d19e0a94f85605af18cacb0c": {
"Type": "AWS::Lambda::Version",
"Properties": {
"FunctionName": {
Expand All @@ -101,7 +101,7 @@
},
"FunctionVersion": {
"Fn::GetAtt": [
"HandlerVersion1F237F6D0",
"HandlerCurrentVersion93FB80BFa1c6e812d19e0a94f85605af18cacb0c",
"Version"
]
},
Expand Down Expand Up @@ -586,4 +586,4 @@
"Description": "Artifact hash for asset \"93dbd8c02dbfca9077c9d83cb6d3a94659988c7d143988da4a554033a58f963c\""
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const handler = new lambda.Function(stack, 'Handler', {
handler: 'index.handler',
runtime: lambda.Runtime.NODEJS_10_X,
});
const version = handler.addVersion('1');
const version = handler.currentVersion;
const blueGreenAlias = new lambda.Alias(stack, 'Alias', {
aliasName: 'alias',
version,
Expand Down
Loading

0 comments on commit 77b573b

Please sign in to comment.