Skip to content

(aws-lambda): support PrincipalOrgId on lambda permissions to allow function access to an AWS organization #19538

@yashaslokesh

Description

@yashaslokesh

What is the problem?

The .addPermission() and .grantInvoke() functions do not allow adding an AWS Organizations ID for resource-based policies. This is a feature in the AWS CLI, as seen here in the docs. I get an error when I try to add an organizations ID as a condition.

Reproduction Steps

Let orgFunction be any Function, then

const permission = new iam.AnyPrincipal()
    .withConditions({
        StringEquals: {
            'aws:PrincipalOrgID': config.organizations.orgId[props.stage]
        }
    });

orgFunction.grantInvoke(permission);

What did you expect to happen?

Expected the CDK synthesis to be successful

What actually happened?

Error: PrincipalWithConditions had unsupported conditions for Lambda permission statement: [{"operator":"StringEquals","key":"aws:PrincipalOrgID"}]. Supported operator/condition pairs: [{"operator":"ArnLike","key":"aws:SourceArn"},{"operator":"StringEquals","key":"aws:SourceAccount"}]

CDK CLI Version

Don't use the CDK CLI

Framework Version

1.149.0

Node.js Version

14.x

OS

Amazon Linux 2 x86_64

Language

Typescript

Language Version

Typescript (3.9.10)

Other information

grantInvoke calls addPermission which calls parsePermissionPrincipal and parseConditions.

parsePermissionsPrincipal should allow an
OrganizationPrincipal and parseConditions should allow the principal condition { operator: 'StringEquals', key: 'aws:PrincipalOrgID' } to conform to the AddPermission functionality presented here, linked earlier.

Metadata

Metadata

Assignees

Labels

@aws-cdk/aws-lambdaRelated to AWS Lambdaeffort/smallSmall work item – less than a day of effortfeature-requestA feature should be added or improved.p1

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions