sykang808 / spring-cloud-aws-example

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Getting Started with Spring Boot on AWS

This source code refers to a blog article we've published as part of the AWS Open Source Blog:

Demo

UPDATE: As Spring Cloud AWS is no longer part of the Spring Cloud release train, the sample application has been migrated to the successor awspring. Read more about the rationale behind this move here.

How to run the demo application

  1. Make sure you have the AWS CLI installed and configured a stratospheric profile with the correct credentials and AWS region e.g.:

Content of ~/.aws/config:

[default]
region = eu-central-1

[profile stratospheric]
region = eu-central-1

Content of ~/.aws/credentials:

[default]
aws_access_key_id=DEFAULT_KEY
aws_secret_access_key=DEFAULT_SECRET

[stratospheric]
aws_access_key_id=XYZ
aws_secret_access_key=XYZ
  1. Ensure you have JDK 17 installed: java -version
  2. Create the required infrastructure for the application (make sure to replace your-unique-bucket-name with a globally unique name):
cd cloudformation
./create.sh your-unique-bucket-name

Please note that for demonstration purposes the S3 Bucket and its content is publicly accessible. Remove it afterwards.

  1. Create at least the following two parameters using the AWS Parameter Store (inside SSM):
/config/stratospheric-demo/custom.bucket-name -> the S3 bucket name you passed to ./create.sh
/config/stratospheric-demo/custom.sqs-queue-name -> stratospheric-demo-queue

The parameter values can be either String or SecureString

  1. Start the application on your local machine:
./gradlew bootRun
  1. Upload the demo images to your S3 bucket (make sure to replace your-unique-bucket-name)
aws s3api put-object --bucket your-unique-bucket-name --key stratospheric-book.pdf --body docs/stratospheric-book.pdf --acl public-read --profile stratospheric
aws s3api put-object --bucket your-unique-bucket-name --key stratospheric-book-cover.jpg --body docs/stratospheric-book-cover.jpg --acl public-read --profile stratospheric
aws s3api put-object --bucket your-unique-bucket-name --key stratospheric-book-cover-mockup.jpg --body docs/stratospheric-book-cover-mockup.jpg --acl public-read --profile stratospheric
  1. Visit http://localhost:8080/ to open the file viewer. In addition to this, you should see incoming log messages from the SQS listener.
  2. (Optional) Build and run the application inside a Docker Container
./gradlew assemble
docker build -t statospheric-demo .
docker run -p 8080:8080 -e AWS_REGION=eu-central-1 -e AWS_ACCESS_KEY_ID=XYZ -e AWS_SECRET_KEY=SECRET stratospheric-demo
  1. Make sure to clean up all AWS resources afterwards. Empty all files within your S3 bucket and then delete the CloudFormation stack inside the AWS console.

Further resources

Authors

About


Languages

Language:Java 55.6%Language:HTML 39.6%Language:Shell 3.9%Language:Dockerfile 0.9%