A basic pet store written with the Apache Struts framework. The Struts2LambdaHandler
object provided by the aws-serverless-java-container-struts2
is the main entry point for Lambda.
The application can be deployed in an AWS account using the Serverless Application Model. The sam.yaml
file in the root folder contains the application definition
To build and install the sample application you will need Maven and the AWS CLI installed on your computer.
In a shell, navigate to the sample's folder and use maven to build a deployable jar.
$ mvn package
This command should generate a serverless-struts-example-1.0-SNAPSHOT.jar
in the target
folder. Now that we have generated the zip file, we can use the AWS CLI to package the template for deployment.
You will need an S3 bucket to store the artifacts for deployment. Once you have created the S3 bucket, run the following command from the sample's folder:
$ aws cloudformation package --template-file sam.yaml --output-template-file output-sam.yaml --s3-bucket <YOUR S3 BUCKET NAME>
Uploading to xxxxxxxxxxxxxxxxxxxxxxxxxx 6464692 / 6464692.0 (100.00%)
Successfully packaged artifacts and wrote output template to file output-sam.yaml.
Execute the following command to deploy the packaged template
aws cloudformation deploy --template-file /your/path/output-sam.yaml --stack-name <YOUR STACK NAME>
As the command output suggests, you can now use the cli to deploy the application. Choose a stack name and run the aws cloudformation deploy
command from the output of the package command.
$ aws cloudformation deploy --template-file output-sam.yaml --stack-name ServerlessSpringSample --capabilities CAPABILITY_IAM
Once the application is deployed, you can describe the stack to show the API endpoint that was created. The endpoint should be the SparkPetStoreApi
key of the Outputs
property:
$ aws cloudformation describe-stacks --stack-name ServerlessSpringSample
{
"Stacks": [
{
"StackId": "arn:aws:cloudformation:us-west-2:xxxxxxxx:stack/JerseySample/xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxx",
"Description": "Example Pet Store API written with Apache Struts with the aws-serverless-java-container library",
"Tags": [],
"Outputs": [
{
"Description": "URL for application",
"OutputKey": "PetStoreApi",
"OutputValue": "https://xxxxxxx.execute-api.us-west-2.amazonaws.com/Prod/pets"
}
],
"CreationTime": "2016-12-13T22:59:31.552Z",
"Capabilities": [
"CAPABILITY_IAM"
],
"StackName": "StrutsSample",
"NotificationARNs": [],
"StackStatus": "UPDATE_COMPLETE"
}
]
}
Copy the OutputValue
into a browser to test a first request.