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

feat(lambda): function URLs #19817

Merged
merged 11 commits into from
Apr 11, 2022
Merged

feat(lambda): function URLs #19817

merged 11 commits into from
Apr 11, 2022

Conversation

ayush987goyal
Copy link
Contributor

feat(aws-lambda): Add support for function URL

closes #19798

Refs:

  1. https://docs.aws.amazon.com/lambda/latest/dg/urls-configuration.html#urls-cfn
  2. https://docs.aws.amazon.com/lambda/latest/dg/API_CreateFunctionUrlConfig.html

All Submissions:

Adding new Unconventional Dependencies:

  • This PR adds new unconventional dependencies following the process described here

New Features

  • Have you added the new feature to an integration test?
    • Did you use cdk-integ to deploy the infrastructure and generate the snapshot (i.e. cdk-integ without --dry-run)?

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@gitpod-io
Copy link

gitpod-io bot commented Apr 8, 2022

@github-actions github-actions bot added effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. p1 labels Apr 8, 2022
@aws-cdk-automation aws-cdk-automation requested a review from a team April 8, 2022 08:21
rix0rrr
rix0rrr previously requested changes Apr 8, 2022
Copy link
Contributor

@rix0rrr rix0rrr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the submission! This will be an exciting feature.

packages/@aws-cdk/aws-lambda/README.md Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-lambda/README.md Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-lambda/lib/function-url.ts Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-lambda/lib/function-url.ts Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-lambda/lib/function-url.ts Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-lambda/lib/function-base.ts Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-lambda/lib/function-url.ts Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-lambda/lib/function-url.ts Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-lambda/lib/function-url.ts Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-lambda/lib/function-url.ts Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-lambda/package.json Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-lambda/lib/function-url.ts Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-lambda/lib/function-url.ts Outdated Show resolved Hide resolved
@mergify mergify bot dismissed rix0rrr’s stale review April 8, 2022 10:09

Pull request has been modified.

packages/@aws-cdk/aws-lambda/README.md Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-lambda/README.md Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-lambda/README.md Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-lambda/test/function.test.ts Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-lambda/lib/function-url.ts Outdated Show resolved Hide resolved
@jogold
Copy link
Contributor

jogold commented Apr 8, 2022

Two comments/questions:

  1. I see now that the CFN resource is named AWS::Lambda::Url not AWS::Lambda::FunctionUrl, how about dropping the function prefix everywhere in the code (and filename). I think this is more inline with the code base.
  2. more important: I see that updating the TargetFunctionArn and/or Qualifier can be done (CFN) without interruption (= no replacement). This is very useful because it means you can keep the same url when changing the function or qualifier behind it. With the current implementation, the URL is created in the scope of the function/qualifier, so if the function/qualifier changes the URL will always be recreated. I think we need to revert the relation here = have a mapTo() function in the URL resource:
const myApiUrl = new Url(this, 'MyApiUrl', { authType: FunctionUrlAuthType.NONE });
myApiUrl.mapTo(myFn);

(making some tests now with CFN to confirm this)

@rix0rrr wdyt?

@jogold
Copy link
Contributor

jogold commented Apr 8, 2022

2. more important: I see that updating the TargetFunctionArn and/or Qualifier can be done (CFN) without interruption (= no replacement). This is very useful because it means you can keep the same url when changing the function or qualifier behind it. With the current implementation, the URL is created in the scope of the function/qualifier, so if the function/qualifier changes the URL will always be recreated. I think we need to revert the relation here = have a mapTo() function in the URL resource:

Unfortunately the doc is incorrect here...

image

VS

image

😢

@ayush987goyal
Copy link
Contributor Author

@jogold Regarding the FunctionUrl nomenclature, the Lambda documentation and console refer to them as Function URLs instead of just URLs. Also, there might be cases where just URL might be confused with URL from the default node engine modules.

@rix0rrr @kaizen3031593 Can we please try to merge this change?

@rix0rrr
Copy link
Contributor

rix0rrr commented Apr 11, 2022

const myApiUrl = new Url(this, 'MyApiUrl', { authType: FunctionUrlAuthType.NONE });
myApiUrl.mapTo(myFn);

Isn't this effectively the same as:

new Url(this, 'MyApiUrl', { 
  authType: ...,
  function: myFn,
});

? Which you can already do?

@jogold
Copy link
Contributor

jogold commented Apr 11, 2022

const myApiUrl = new Url(this, 'MyApiUrl', { authType: FunctionUrlAuthType.NONE });
myApiUrl.mapTo(myFn);

Isn't this effectively the same as:

new Url(this, 'MyApiUrl', { 
  authType: ...,
  function: myFn,
});

? Which you can already do?

Yes

Copy link
Contributor

@rix0rrr rix0rrr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would also like to see a grantInvokeUrl method. It should probably be both on IFunction as well as on FunctionUrl, so it will be wherever people think to look.

Can we also add in documentation to say what the response object of the Lambda should be? ({ statusCode, body, [headers, cookies, isBase64Encoded] })

packages/@aws-cdk/aws-lambda/lib/function-url.ts Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-lambda/README.md Outdated Show resolved Hide resolved
@rix0rrr rix0rrr changed the title feat(aws-lambda): Add support for function URL feat(lambda): function URLs Apr 11, 2022
packages/@aws-cdk/aws-lambda/lib/function-url.ts Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-lambda/lib/function-url.ts Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-lambda/lib/function-url.ts Outdated Show resolved Hide resolved
@mergify mergify bot dismissed rix0rrr’s stale review April 11, 2022 12:51

Pull request has been modified.

rix0rrr
rix0rrr previously approved these changes Apr 11, 2022
@mergify
Copy link
Contributor

mergify bot commented Apr 11, 2022

Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@mergify mergify bot dismissed rix0rrr’s stale review April 11, 2022 16:44

Pull request has been modified.

@mergify
Copy link
Contributor

mergify bot commented Apr 11, 2022

Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject89A8053A-LhjRyN9kxr8o
  • Commit ID: bd6704c
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mergify mergify bot merged commit 4fd515a into aws:master Apr 11, 2022
@mergify
Copy link
Contributor

mergify bot commented Apr 11, 2022

Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@ayush987goyal ayush987goyal deleted the pr/function-url branch April 12, 2022 02:40
StevePotter pushed a commit to StevePotter/aws-cdk that referenced this pull request Apr 27, 2022
feat(aws-lambda): Add support for function URL

closes aws#19798 

Refs:
1. https://docs.aws.amazon.com/lambda/latest/dg/urls-configuration.html#urls-cfn
2. https://docs.aws.amazon.com/lambda/latest/dg/API_CreateFunctionUrlConfig.html

----

### All Submissions:

* [x] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md)

### Adding new Unconventional Dependencies:

* [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md/#adding-new-unconventional-dependencies)

### New Features

* [x] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/master/INTEGRATION_TESTS.md)?
	* [x] Did you use `cdk-integ` to deploy the infrastructure and generate the snapshot (i.e. `cdk-integ` without `--dry-run`)?

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. p1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

(aws-lambda): Add support for Function URLs
6 participants