Skip to content

Commit

Permalink
refactor(cloudfront): replace instanceOf into Role.isRole() methodd (#…
Browse files Browse the repository at this point in the history
…24448)

Closes #24447 

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
bun913 authored Mar 3, 2023
1 parent e8e5cdc commit 29bdd6c
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ interface FunctionConfig {
}

function addEdgeLambdaToRoleTrustStatement(role: iam.IRole) {
if (role instanceof iam.Role && role.assumeRolePolicy) {
if (iam.Role.isRole(role) && role.assumeRolePolicy) {
const statement = new iam.PolicyStatement();
const edgeLambdaServicePrincipal = new iam.ServicePrincipal('edgelambda.amazonaws.com');
statement.addPrincipals(edgeLambdaServicePrincipal);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export class CacheBehavior {
if (!edgeLambdas || edgeLambdas.length === 0) { return; }
edgeLambdas.forEach((edgeLambda) => {
const role = edgeLambda.functionVersion.role;
if (role && role instanceof iam.Role && role.assumeRolePolicy) {
if (role && iam.Role.isRole(role) && role.assumeRolePolicy) {
role.assumeRolePolicy.addStatements(new iam.PolicyStatement({
actions: ['sts:AssumeRole'],
principals: [new iam.ServicePrincipal('edgelambda.amazonaws.com')],
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-cloudfront/lib/web-distribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1053,7 +1053,7 @@ export class CloudFrontWebDistribution extends cdk.Resource implements IDistribu

// allow edgelambda.amazonaws.com to assume the functions' execution role.
for (const a of input.lambdaFunctionAssociations) {
if (a.lambdaFunction.role && a.lambdaFunction.role instanceof iam.Role && a.lambdaFunction.role.assumeRolePolicy) {
if (a.lambdaFunction.role && iam.Role.isRole(a.lambdaFunction.role) && a.lambdaFunction.role.assumeRolePolicy) {
a.lambdaFunction.role.assumeRolePolicy.addStatements(new iam.PolicyStatement({
actions: ['sts:AssumeRole'],
principals: [new iam.ServicePrincipal('edgelambda.amazonaws.com')],
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-codepipeline/lib/pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,7 @@ export class Pipeline extends PipelineBase {
// because the role might be from a different environment),
// but _only_ if it's a new Role -
// an imported Role should not add the dependency
if (action.actionProperties.role instanceof iam.Role) {
if (iam.Role.isRole(action.actionProperties.role)) {
const roleStack = Stack.of(action.actionProperties.role);
pipelineStack.addDependency(roleStack);
}
Expand Down

0 comments on commit 29bdd6c

Please sign in to comment.