aws / aws-cdk

The AWS Cloud Development Kit is a framework for defining cloud infrastructure in code
https://aws.amazon.com/cdk
Apache License 2.0
11.54k stars 3.86k forks source link

Lambda Alias AppSync Resolvers #15321

Closed romanfq closed 3 years ago

romanfq commented 3 years ago

Allow a Lambda Data Source that can point to an alias

Use Case

When using Provisioned Concurrency today in a Lambda- for lower cold-starts- an alias gets created, which is usually called live. The ARN of this alias is that of the Lambda Function with a :live suffix.

Now, when a lambda data source is added to an AppSync API, the data source is pointing to the Lambda function and not the the alias, and then calls from AppSync don't call the alias but the $LATEST version of the function (no idea why this doesn't work). This defeats Provisioned Concurrency.

There's a manual workaround: after deploying the AppSync API and the Lambda, you can go to the console and

Proposed Solution

Add native support to the CDK to generate an Alias datasource, similar to

const alias = ...
const aliasDs: LambdaAliasDataSource = this.appSync.addLambdaAliasDataSource("LambdaDataSource", alias);

or simply add an override to addLambdaDataSource that allows to supply an alias

const alias = ...
const lambdaDs: LambdaDataSource = this.appSync.addLambdaAliasDataSource("LambdaDataSource", lambdaFunction, alias);

I tried to simulate the same by creating my own types under the DataSource hierarchies (i.e. creating a new sub-type of BackedDataSource and forcing a grantInvoke on the IAM role for the alias but it didn't work well- I might post repro code at some later stage.


This is a :rocket: Feature Request

otaviomacedo commented 3 years ago

Hi, @romanfq

I am unassigning and marking this issue as p2, which means that we are unable to work on this immediately.

We use +1s to help prioritize our work, and are happy to revaluate this issue based on community feedback. You can reach out to the cdk.dev community on Slack to solicit support for reprioritization.

BryanPan342 commented 3 years ago

@romanfq I'm surprised you can't just run

const alias = ...
api.addLambdaDataSource('LambdaDataSource', alias);

addLambdaDataSource takes IFunction as the property type which Version and Alias extend from...

github-actions[bot] commented 3 years ago

This issue has not received a response in a while. If you want to keep this issue open, please leave a comment below and auto-close will be canceled.