AWS SAM Cdk - Dependency on Lambda Alias

16 Views Asked by At

I have an issue in aws-sam cdk. I have a lambda with "AutoPublishAlias" and an api gateway. The apigateway has a permission to the lambda's alias and is set like this:

const permission = new aws_lambda.CfnPermission(scope, `${lambda.node.id}InvokeAliasPermissions`, {
    action: 'lambda:InvokeFunction',
    functionName: `function:${lambda.functionName}:${lambda.autoPublishAlias}`,
    principal: 'apigateway.amazonaws.com',
    sourceArn: cdk.Fn.sub(`arn:aws:execute-api:\${AWS::Region}:\${AWS::AccountId}:\${${api.logicalId}}/*/*/*`),
  });
  permission.addDependency(lambda);

But I get the following error: Cannot find alias arn: ...

It seems that I need to add a dependency to the lambda's alias and not the lambda instead, however, I couldn't find how to do that with cdk, since the addDependency method requires a CfnResource type, but I dont have it for the alias since I'm using sam with "AutoPublishAlias".

I've seen the following question but it uses Ref and I didn't find how to do that using cdk.

Any idea how to do that?

0

There are 0 best solutions below