-
Notifications
You must be signed in to change notification settings - Fork 136
SpringBoot Response Streaming using function url #237
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
f58af26
Adding a new example that uses springboot for streaming
soyer-dev 3e8f71c
Updated readme and added the sample output.
soyer-dev 169f459
Updated readme and added the sample output.
soyer-dev 1221f4d
.DS_Store banished!
soyer-dev f341f7e
.DS_Store banished!
soyer-dev 589888b
Updated readme and added the sample output.
soyer-dev 83b42c3
Optimized imports
soyer-dev f98eb1e
Optimized imports
soyer-dev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
HELP.md | ||
target/ | ||
!app/.mvn/wrapper/maven-wrapper.jar | ||
!**/src/main/**/target/ | ||
!**/src/test/**/target/ | ||
|
||
### STS ### | ||
.apt_generated | ||
.classpath | ||
.factorypath | ||
.project | ||
.settings | ||
.springBeans | ||
.sts4-cache | ||
.DS_Store | ||
|
||
### IntelliJ IDEA ### | ||
.idea | ||
*.iws | ||
*.iml | ||
*.ipr | ||
|
||
### NetBeans ### | ||
/nbproject/private/ | ||
/nbbuild/ | ||
/dist/ | ||
/nbdist/ | ||
/.nb-gradle/ | ||
build/ | ||
!**/src/main/**/build/ | ||
!**/src/test/**/build/ | ||
|
||
### VS Code ### | ||
.vscode/ | ||
|
||
.mvn | ||
.aws-sam |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
11.0.14 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
# Spring Boot 2 Zip example | ||
|
||
A basic file streaming application written with the Spring Boot 2 framework. You can build and test it locally as a typical Spring Boot 2 application. | ||
|
||
The application can be deployed in an AWS account using the [Serverless Application Model](https://github.com/awslabs/serverless-application-model). The `template.yaml` file in the root folder contains the application definition. | ||
|
||
To run the application we are using the run.sh script located in the resources folder: | ||
|
||
```shell | ||
#!/bin/sh | ||
|
||
exec java -cp "./:lib/*" "com.amazonaws.demo.stream.Application" | ||
``` | ||
|
||
In the configuration we have to specify the AWS Lambda adapter as a layer and configure the script as handler: | ||
|
||
```yaml | ||
Properties: | ||
MemorySize: 512 | ||
Handler: run.sh | ||
CodeUri: app/ | ||
Runtime: java11 | ||
AutoPublishAlias: live | ||
SnapStart: | ||
ApplyOn: PublishedVersions | ||
Environment: | ||
Variables: | ||
RUST_LOG: info | ||
READINESS_CHECK_PATH: /healthz | ||
REMOVE_BASE_PATH: /v1 | ||
AWS_LAMBDA_EXEC_WRAPPER: /opt/bootstrap | ||
AWS_LWA_INVOKE_MODE: response_stream | ||
Layers: | ||
- !Sub arn:aws:lambda:${AWS::Region}:753240598075:layer:LambdaAdapterLayerX86:16 | ||
``` | ||
In this template, we enable SnapStart for this function. SnapStart drastically reduces cold start time for Java functions using Firecracker MicroVM snapshotting technology. Read more about SnapStart [here](https://docs.aws.amazon.com/lambda/latest/dg/snapstart.html). | ||
|
||
### Remove the base path | ||
|
||
The file stream application is deployed under /v1/{proxy+}. But the application does not know that. So in the SAM template file, we configured environment variable `REMOVE_BASE_PATH=/v1`. | ||
This configuration tells the Adapter to remove `/v1` from http request path, so that the pet store application works without changing code. | ||
|
||
|
||
## Pre-requisites | ||
|
||
The following tools should be installed and configured. | ||
|
||
* [AWS CLI](https://aws.amazon.com/cli/) | ||
* [SAM CLI](https://github.com/awslabs/aws-sam-cli) | ||
* [Maven](https://maven.apache.org/) | ||
* [Docker](https://www.docker.com/products/docker-desktop) | ||
|
||
## Deploy to Lambda | ||
Navigate to the sample's folder and use the SAM CLI to build the application: | ||
|
||
```shell | ||
$ sam build | ||
``` | ||
|
||
This command compiles the application and prepares a deployment package in the `.aws-sam` sub-directory. | ||
|
||
To deploy the application in your AWS account, you can use the SAM CLI's guided deployment process and follow the instructions on the screen | ||
|
||
```shell | ||
$ sam deploy --guided | ||
``` | ||
|
||
Once the deployment is completed, the SAM CLI will print out the stack's outputs, including the new application URL. You can use `curl` or a web browser to make a call to the URL | ||
|
||
```shell | ||
... | ||
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ||
Outputs | ||
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ||
Key StreamFilesFunctionUrl | ||
Description Function URL for StreamFiles function to stream a dummy 15mb file | ||
Value https://abcdxxxxxxxxxxxx.lambda-url.us-west-2.on.aws/stream-dummy?size=15 | ||
|
||
Key StreamFilesFunction | ||
Description StreamFilesFunction Lambda Function ARN | ||
Value arn:aws:lambda:us-west-2:111111111111:function:spring-wa-StreamFilesFunction-abcdxxxxxxxxxxxx | ||
... | ||
|
||
$ curl https://abcdxxxxxxxxxxxx.lambda-url.us-west-2.on.aws/stream-dummy?size=15 | ||
|
||
To stream a preexisting mp4 file | ||
|
||
$ curl https://abcdxxxxxxxxxxxx.lambda-url.us-west-2.on.aws/stream | ||
``` | ||
|
||
## Clean up | ||
|
||
This example use provisioned concurrency to reduce cold start time. It incurs additional cost. You can remove the whole example with the following command. | ||
|
||
```shell | ||
sam delete | ||
``` |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.