-
Notifications
You must be signed in to change notification settings - Fork 90
docs: Add Serveless Framework example #1363
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
scottgerring
merged 29 commits into
aws-powertools:main
from
AlexeySoshin:serverless-example
Sep 28, 2023
Merged
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
c107f8f
Initial
AlexeySoshin c405cbb
Add memory size and timeouts, same as SAM examples
AlexeySoshin 6896dbd
Add useful Serverless commands
AlexeySoshin a4a6445
Remove redundant function
AlexeySoshin 3a2e6e4
Update examples/powertools-examples-core/serverless/README.md
AlexeySoshin 8e59d86
Update examples/powertools-examples-core/serverless/README.md
AlexeySoshin c2b2093
Update examples/powertools-examples-core/serverless/README.md
AlexeySoshin 203298a
Update examples/powertools-examples-core/serverless/README.md
AlexeySoshin c3e5f43
Merge branch 'main' of https://github.com/aws-powertools/powertools-l…
AlexeySoshin 134b9de
Update examples/powertools-examples-core/serverless/README.md
AlexeySoshin ca596dc
Merge branch 'main' of https://github.com/aws-powertools/powertools-l…
AlexeySoshin 4f6eaee
Remove reduntant command from README
AlexeySoshin 0de614f
Move most of Powertools configuration to the service-wide environment
AlexeySoshin 917f3f7
Merge branch 'main' into serverless-example
scottgerring c28e144
Merge branch 'main' of https://github.com/aws-powertools/powertools-l…
AlexeySoshin d76ff02
Merge branch 'serverless-example' of https://github.com/AlexeySoshin/…
AlexeySoshin d7b7d75
Merge branch 'main' of https://github.com/aws-powertools/powertools-l…
AlexeySoshin 1b9d148
Remove more generated comments
AlexeySoshin 0d7703d
Merge branch 'main' of https://github.com/aws-powertools/powertools-l…
AlexeySoshin 86e9744
Add newlines
AlexeySoshin b96bb90
Comment out annotations that are preceded by environment variables
AlexeySoshin 20fd3b9
Add link to the Serverless example
AlexeySoshin 802b149
Merge branch 'main' of https://github.com/aws-powertools/powertools-l…
AlexeySoshin 099bb0a
Merge branch 'main' of https://github.com/aws-powertools/powertools-l…
AlexeySoshin 5471f77
Update examples/powertools-examples-core/serverless/pom.xml
AlexeySoshin 3e6e889
Update examples/powertools-examples-core/serverless/pom.xml
AlexeySoshin 0287452
Update examples/powertools-examples-core/serverless/pom.xml
AlexeySoshin 7e66b9d
Remove POWERTOOLS_LOGGER_LOG_EVENT, since it's unsupported
AlexeySoshin 8c04c27
Merge branch 'main' into serverless-example
scottgerring 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
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
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
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,26 @@ | ||
# Powertools for AWS Lambda (Java) - Core Utilities Example with Serverless Framework | ||
|
||
This project demonstrates the Lambda for Powertools Java module deployed using [Serverless Framework](https://www.serverless.com/framework). | ||
For general information on the deployed example itself, you can refer to the parent [README](../README.md). | ||
To install Serverless Framework if you don't have it yet, you can follow the [Getting Started Guide](https://www.serverless.com/framework/docs/getting-started). | ||
|
||
## Configuration | ||
Serverless Framework uses [serverless.yml](./serverless.yml) to define the application's AWS resources. | ||
This file defines the Lambda function to be deployed as well as API Gateway for it. | ||
|
||
It is a [Maven](https://maven.apache.org/) based project, so you can open this project with any Maven compatible Java IDE to build and run tests. | ||
|
||
|
||
## Deploy the sample application | ||
|
||
To deploy the app, simply run the following commands: | ||
```bash | ||
mvn package && sls deploy | ||
``` | ||
|
||
## Useful commands | ||
|
||
Deploy a single function | ||
```bash | ||
sls deploy function -f hello | ||
``` |
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,209 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>software.amazon.lambda.examples</groupId> | ||
<version>1.18.0-SNAPSHOT</version> | ||
<artifactId>powertools-examples-core-serverless</artifactId> | ||
<packaging>jar</packaging> | ||
|
||
<name>Powertools for AWS Lambda (Java) library Examples - Core</name> | ||
|
||
<properties> | ||
<log4j.version>2.20.0</log4j.version> | ||
<maven.compiler.source>1.8</maven.compiler.source> | ||
<maven.compiler.target>1.8</maven.compiler.target> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>software.amazon.lambda</groupId> | ||
<artifactId>powertools-tracing</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>software.amazon.lambda</groupId> | ||
<artifactId>powertools-logging</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>software.amazon.lambda</groupId> | ||
<artifactId>powertools-metrics</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.amazonaws</groupId> | ||
<artifactId>aws-lambda-java-core</artifactId> | ||
<version>1.2.2</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.amazonaws</groupId> | ||
<artifactId>aws-lambda-java-events</artifactId> | ||
<version>3.11.2</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.logging.log4j</groupId> | ||
<artifactId>log4j-core</artifactId> | ||
<version>${log4j.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.logging.log4j</groupId> | ||
<artifactId>log4j-api</artifactId> | ||
<version>${log4j.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>4.13.2</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<finalName>helloworld-lambda</finalName> | ||
<plugins> | ||
<plugin> | ||
<groupId>dev.aspectj</groupId> | ||
<artifactId>aspectj-maven-plugin</artifactId> | ||
<version>1.13.1</version> | ||
<configuration> | ||
<source>${maven.compiler.source}</source> | ||
<target>${maven.compiler.target}</target> | ||
<complianceLevel>${maven.compiler.target}</complianceLevel> | ||
<aspectLibraries> | ||
<aspectLibrary> | ||
<groupId>software.amazon.lambda</groupId> | ||
<artifactId>powertools-tracing</artifactId> | ||
</aspectLibrary> | ||
<aspectLibrary> | ||
<groupId>software.amazon.lambda</groupId> | ||
<artifactId>powertools-logging</artifactId> | ||
</aspectLibrary> | ||
<aspectLibrary> | ||
<groupId>software.amazon.lambda</groupId> | ||
<artifactId>powertools-metrics</artifactId> | ||
</aspectLibrary> | ||
</aspectLibraries> | ||
</configuration> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>compile</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-shade-plugin</artifactId> | ||
<version>3.5.0</version> | ||
<executions> | ||
<execution> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>shade</goal> | ||
</goals> | ||
<configuration> | ||
<transformers> | ||
<transformer | ||
implementation="com.github.edwgiz.maven_shade_plugin.log4j2_cache_transformer.PluginsCacheFileTransformer"> | ||
</transformer> | ||
</transformers> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
<dependencies> | ||
<dependency> | ||
<groupId>com.github.edwgiz</groupId> | ||
<artifactId>maven-shade-plugin.log4j2-cachefile-transformer</artifactId> | ||
<version>2.15</version> | ||
</dependency> | ||
</dependencies> | ||
</plugin> | ||
AlexeySoshin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<!-- Don't deploy the example --> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-deploy-plugin</artifactId> | ||
<configuration> | ||
<skip>true</skip> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
<profiles> | ||
<!-- Use a profile to enforce AspectJ version 1.9.7 if we are Java 1.8 otherwise we'll get class | ||
version mismatch issues. All subsequent Java releases build with the default AspectJ configuration | ||
on the project. | ||
|
||
Note: | ||
- if you are running Java > 1.8, you can remove this profile altogether | ||
- If you are running on Java 1.8, you should apply the aspectJ version here to the project, and remove | ||
the profile. | ||
--> | ||
<profile> | ||
<id>jdk8</id> | ||
<activation> | ||
<jdk>(,11)</jdk> <!-- 8 --> | ||
</activation> | ||
<properties> | ||
<aspectj.version>1.9.7</aspectj.version> | ||
</properties> | ||
<dependencyManagement> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.aspectj</groupId> | ||
<artifactId>aspectjtools</artifactId> | ||
<version>${aspectj.version}</version> | ||
</dependency> | ||
</dependencies> | ||
</dependencyManagement> | ||
<build> | ||
<pluginManagement> | ||
<plugins> | ||
<plugin> | ||
<groupId>dev.aspectj</groupId> | ||
<artifactId>aspectj-maven-plugin</artifactId> | ||
<version>${aspectj.plugin.version}</version> | ||
<configuration> | ||
<source>${maven.compiler.source}</source> | ||
<target>${maven.compiler.target}</target> | ||
<complianceLevel>${maven.compiler.target}</complianceLevel> | ||
<aspectLibraries> | ||
<aspectLibrary> | ||
<groupId>software.amazon.lambda</groupId> | ||
<artifactId>powertools-tracing</artifactId> | ||
</aspectLibrary> | ||
<aspectLibrary> | ||
<groupId>software.amazon.lambda</groupId> | ||
<artifactId>powertools-logging</artifactId> | ||
</aspectLibrary> | ||
<aspectLibrary> | ||
<groupId>software.amazon.lambda</groupId> | ||
<artifactId>powertools-metrics</artifactId> | ||
</aspectLibrary> | ||
</aspectLibraries> | ||
</configuration> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>compile</goal> | ||
<goal>test-compile</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
<!-- Enforce aspectJ 1.9.7 --> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.aspectj</groupId> | ||
<artifactId>aspectjtools</artifactId> | ||
<version>${aspectj.version}</version> | ||
</dependency> | ||
</dependencies> | ||
</plugin> | ||
</plugins> | ||
</pluginManagement> | ||
</build> | ||
</profile> | ||
</profiles> | ||
</project> |
40 changes: 40 additions & 0 deletions
40
examples/powertools-examples-core/serverless/serverless.yml
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,40 @@ | ||
service: hello | ||
# app and org for use with dashboard.serverless.com | ||
#app: your-app-name | ||
#org: your-org-name | ||
|
||
# You can pin your service to only deploy with a specific Serverless version | ||
# Check out our docs for more details | ||
frameworkVersion: '3' | ||
|
||
provider: | ||
name: aws | ||
runtime: java11 | ||
jeromevdl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
# you can overwrite defaults here | ||
# stage: dev | ||
# region: us-east-1 | ||
|
||
# you can define service wide environment variables here | ||
environment: | ||
POWERTOOLS_LOG_LEVEL: INFO | ||
POWERTOOLS_LOGGER_SAMPLE_RATE: 0.1 | ||
POWERTOOLS_METRICS_NAMESPACE: Coreutilities | ||
|
||
# you can add packaging information here | ||
package: | ||
artifact: target/helloworld-lambda.jar | ||
|
||
functions: | ||
hello: | ||
handler: helloworld.App | ||
memorySize: 512 | ||
timeout: 20 | ||
tracing: "Active" | ||
events: | ||
- httpApi: | ||
path: /hello | ||
method: get | ||
# Define function environment variables here | ||
environment: | ||
POWERTOOLS_SERVICE_NAME: hello |
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.