Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lambda.Function.lambda_from_arn doesn't work like a Lambda #23296

Closed
noesnaterse opened this issue Dec 9, 2022 · 2 comments
Closed

Lambda.Function.lambda_from_arn doesn't work like a Lambda #23296

noesnaterse opened this issue Dec 9, 2022 · 2 comments
Assignees
Labels
@aws-cdk/aws-lambda Related to AWS Lambda bug This issue is a bug.

Comments

@noesnaterse
Copy link

Describe the bug

Lambda.Function.function_from_arn doesn't produce a Lambda function

Expected Behavior

I expected to call any methods I call on a Lambda function from ARN as I can do on a real Lambda

Current Behavior

This works

my_lambda = lambda_.Function(
    self,
    "my_lambda",
    function_name="my_lambda",
    description="A Lambda to test permissions",
    code=lambda_code,
    memory_size=512,
    handler="my_lambda.main",
    runtime=lambda_.Runtime.PYTHON_3_9,
    architecture=lambda_.Architecture.ARM_64,
    timeout=Duration.minutes(1),
)


table = dynamodb.Table(
    self,
    'test_table',
    partition_key=dynamodb.Attribute(
        name="id",
        type=dynamodb.AttributeType.STRING,
    ),
)
table.grant_full_access(my_lambda)

Reproduction Steps

This doesn't work

my_lambda = lambda_.Function(
    self,
    "my_lambda",
    function_name="my_lambda",
    description="A Lambda to test permissions",
    code=lambda_code,
    memory_size=512,
    handler="my_lambda.main",
    runtime=lambda_.Runtime.PYTHON_3_9,
    architecture=lambda_.Architecture.ARM_64,
    timeout=Duration.minutes(1),
)


table = dynamodb.Table(
    self,
    'test_table',
    partition_key=dynamodb.Attribute(
        name="id",
        type=dynamodb.AttributeType.STRING,
    ),
)

s3_by_arn = lambda_.Function.from_function_arn(
            self,
            "s3object_lambda_appsync_by_proxy",
            s3object_lambda.function_arn
        )
table.grant_full_access(s3_by_arn)

Possible Solution

For me it would help if the reproducion steps would work exactly like the current_behavior step.
A Lambda should work like a Lambda no matter how you obtain it.

Additional Information/Context

I have two different stacks in which I define the Lambda and one in which I define the DynamoDB table, so that is why I use the function_from_arn method to get the Lambda and give it access rights.

CDK CLI Version

2.54.0 (build 9f41881)

Framework Version

V2

Node.js Version

v14.20.0

OS

Linux

Language

Python

Language Version

Python 3.9.13

Other information

No response

@noesnaterse noesnaterse added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Dec 9, 2022
@github-actions github-actions bot added the @aws-cdk/aws-lambda Related to AWS Lambda label Dec 9, 2022
@noesnaterse noesnaterse changed the title (module name): (short issue description) Lambda.Function.lambda_from_arn doesn't work like a Lambda Dec 9, 2022
@peterwoodworth
Copy link
Contributor

This is because the role associated with the Lambda that this function needs to add permissions to is not defined. You can import and associate this role to the lambda function with fromFunctionAttributes()

I expected to call any methods I call on a Lambda function from ARN as I can do on a real Lambda

This won't necessarily be true for any given construct that is imported. See here for more info. Ping me if you have any followup questions, thanks!

@peterwoodworth peterwoodworth removed the needs-triage This issue or PR still needs to be triaged. label Dec 9, 2022
@github-actions
Copy link

github-actions bot commented Dec 9, 2022

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-lambda Related to AWS Lambda bug This issue is a bug.
Projects
None yet
Development

No branches or pull requests

3 participants