{"id":1065,"date":"2021-07-23T13:57:10","date_gmt":"2021-07-23T20:57:10","guid":{"rendered":"https:\/\/bullyrooks.com\/?p=1065"},"modified":"2021-07-25T06:53:19","modified_gmt":"2021-07-25T13:53:19","slug":"spring-boot-lambda-prerequisites","status":"publish","type":"post","link":"https:\/\/bullyrooks.com\/index.php\/2021\/07\/23\/spring-boot-lambda-prerequisites\/","title":{"rendered":"Spring Boot Lambda Prerequisites"},"content":{"rendered":"\n<p>In this course we&#8217;re going to build a very simple spring boot lambda, deploy it manually to AWS to make sure that it works and then automate the deployment using Terraform and github actions.  This will allow us to automatically build and deploy changes from a commit to the <code>main <\/code>branch.<\/p>\n\n\n\n<p>First off, you&#8217;ll need to setup the following things:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>IntelliJ IDE<\/li><li><a href=\"https:\/\/aws.amazon.com\/premiumsupport\/knowledge-center\/create-and-activate-aws-account\/\">Create an AWS account<\/a><\/li><li><a href=\"https:\/\/docs.github.com\/en\/get-started\/quickstart\/create-a-repo\">Create a new GitHub repository<\/a><\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">New GitHub Repository<\/h2>\n\n\n\n<p>Go ahead and create a new empty github repository.  At the end you should have something like this:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"942\" height=\"395\" src=\"https:\/\/i0.wp.com\/bullyrooks.com\/wp-content\/uploads\/2021\/07\/image.png?resize=942%2C395&#038;ssl=1\" alt=\"\" class=\"wp-image-1066\" srcset=\"https:\/\/i0.wp.com\/bullyrooks.com\/wp-content\/uploads\/2021\/07\/image.png?w=942&amp;ssl=1 942w, https:\/\/i0.wp.com\/bullyrooks.com\/wp-content\/uploads\/2021\/07\/image.png?resize=300%2C126&amp;ssl=1 300w, https:\/\/i0.wp.com\/bullyrooks.com\/wp-content\/uploads\/2021\/07\/image.png?resize=768%2C322&amp;ssl=1 768w\" sizes=\"auto, (max-width: 942px) 100vw, 942px\" data-recalc-dims=\"1\" \/><\/figure>\n\n\n\n<p>clone it to your local workspace by getting the clone command from the green <code>code<\/code> button and execute it locally with the clone command.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ git clone https:\/\/github.com\/bullyrooks\/helloworld-lambda.git\nCloning into 'helloworld-lambda'...\nremote: Enumerating objects: 4, done.\nremote: Counting objects: 100% (4\/4), done.\nremote: Compressing objects: 100% (3\/3), done.\nremote: Total 4 (delta 0), reused 0 (delta 0), pack-reused 0\nUnpacking objects: 100% (4\/4), 850 bytes | 44.00 KiB\/s, done.\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Initialize the Project with Initializr<\/h2>\n\n\n\n<p>The spring assistant plugin doesn&#8217;t work with the newer versions of intellij community unfortunately, so we can build a spring boot project from scratch the old fashioned way.  Head over to <a href=\"https:\/\/start.spring.io\/\">initializr<\/a> and create a new project like this:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"960\" height=\"546\" src=\"https:\/\/i0.wp.com\/bullyrooks.com\/wp-content\/uploads\/2021\/07\/image-1-1024x582.png?resize=960%2C546&#038;ssl=1\" alt=\"\" class=\"wp-image-1067\" srcset=\"https:\/\/i0.wp.com\/bullyrooks.com\/wp-content\/uploads\/2021\/07\/image-1.png?resize=1024%2C582&amp;ssl=1 1024w, https:\/\/i0.wp.com\/bullyrooks.com\/wp-content\/uploads\/2021\/07\/image-1.png?resize=300%2C171&amp;ssl=1 300w, https:\/\/i0.wp.com\/bullyrooks.com\/wp-content\/uploads\/2021\/07\/image-1.png?resize=768%2C437&amp;ssl=1 768w, https:\/\/i0.wp.com\/bullyrooks.com\/wp-content\/uploads\/2021\/07\/image-1.png?w=1405&amp;ssl=1 1405w\" sizes=\"auto, (max-width: 960px) 100vw, 960px\" data-recalc-dims=\"1\" \/><figcaption>Keep in mind that java 11 is the highest version of java that is supported by lambda at the moment.  Also, I&#8217;m using maven and my examples will be using maven.<\/figcaption><\/figure>\n\n\n\n<p>Generate the .zip and extract it into your project directory that you just cloned.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Create a New IntelliJ Project<\/h2>\n\n\n\n<p>Now make a new intellij project from existing sources, point it to your helloworld directory and build it from the maven archetype.<\/p>\n\n\n\n<p>You should have a directory structure similar to this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ ls -al\ntotal 59\ndrwxr-xr-x 1 brian 197609     0 Jul 23 11:32 .\ndrwxr-xr-x 1 brian 197609     0 Jul 23 11:00 ..\ndrwxr-xr-x 1 brian 197609     0 Jul 23 11:32 .git\n-rw-r--r-- 1 brian 197609   474 Jul 23 11:32 .gitignore\ndrwxr-xr-x 1 brian 197609     0 Jul 23 11:31 .idea\ndrwxr-xr-x 1 brian 197609     0 Jul 23 11:06 .mvn\n-rw-r--r-- 1 brian 197609   649 Jul 23  2021 HELP.md\n-rw-r--r-- 1 brian 197609    19 Jul 23 11:00 README.md\n-rw-r--r-- 1 brian 197609  6134 Jul 23 11:28 helloworld-lambda.iml\n-rwxr-xr-x 1 brian 197609 10070 Jul 23  2021 mvnw\n-rw-r--r-- 1 brian 197609  6608 Jul 23  2021 mvnw.cmd\n-rw-r--r-- 1 brian 197609  1585 Jul 23  2021 pom.xml\ndrwxr-xr-x 1 brian 197609     0 Jul 23 11:06 src\n\n<\/code><\/pre>\n\n\n\n<p>now update the .gitignore file to make sure that we&#8217;re not going to pull in anything we don&#8217;t want.  It should look like this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Compiled class file\n*.class\n\n# Log file\n*.log\n\n# BlueJ files\n*.ctxt\n\n# Mobile Tools for Java (J2ME)\n.mtj.tmp\/\n\n# Package Files #\n*.jar\n*.war\n*.nar\n*.ear\n*.zip\n*.tar.gz\n*.rar\n\n# virtual machine crash logs, see http:\/\/www.java.com\/en\/download\/help\/error_hotspot.xml\nhs_err_pid*\n\n### Maven Build\nHELP.md\ntarget\/\n!.mvn\/wrapper\/maven-wrapper.jar\n!**\/src\/main\/**\/target\/\n!**\/src\/test\/**\/target\/\n\n### IntelliJ IDEA ###\n.idea\n*.iws\n*.iml\n*.ipr\n<\/code><\/pre>\n\n\n\n<p>switch over to a new branch:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ git checkout -b initial\nSwitched to a new branch 'initial'\n<\/code><\/pre>\n\n\n\n<p>make sure it builds<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><span class=\"has-inline-color has-vivid-red-color\">$ mvn clean package<\/span>\n...\n&#91;INFO] ------------------------------------------------------------------------\n&#91;INFO] BUILD SUCCESS\n&#91;INFO] ------------------------------------------------------------------------\n&#91;INFO] Total time:  5.885 s\n&#91;INFO] Finished at: 2021-07-23T11:38:45-06:00\n&#91;INFO] ------------------------------------------------------------------------\n<\/code><\/pre>\n\n\n\n<p>check status and commit<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><span class=\"has-inline-color has-vivid-red-color\">$ git status<\/span>\nOn branch initial\nChanges not staged for commit:\n  (use \"git add &lt;file&gt;...\" to update what will be committed)\n  (use \"git restore &lt;file&gt;...\" to discard changes in working directory)\n        modified:   .gitignore\n\nUntracked files:\n  (use \"git add &lt;file&gt;...\" to include in what will be committed)\n        .mvn\/\n        mvnw\n        mvnw.cmd\n        pom.xml\n        src\/\n\nno changes added to commit (use \"git add\" and\/or \"git commit -a\")\n\n<span class=\"has-inline-color has-vivid-red-color\">$ git add .<\/span>\n...\n<span class=\"has-inline-color has-vivid-red-color\">$ git commit -m \"initial commit\"<\/span>\n&#91;initial 82c760e] initial commit\n 10 files changed, 705 insertions(+)\n create mode 100644 .mvn\/wrapper\/MavenWrapperDownloader.java\n create mode 100644 .mvn\/wrapper\/maven-wrapper.jar\n create mode 100644 .mvn\/wrapper\/maven-wrapper.properties\n create mode 100644 mvnw\n create mode 100644 mvnw.cmd\n create mode 100644 pom.xml\n create mode 100644 src\/main\/java\/com\/bullyrooks\/helloworldlambda\/HelloworldLambdaApplication.java\n create mode 100644 src\/main\/resources\/application.properties\n create mode 100644 src\/test\/java\/com\/bullyrooks\/helloworldlambda\/HelloworldLambdaApplicationTests.java\n\n<span class=\"has-inline-color has-vivid-red-color\">$  git push --set-upstream origin initial<\/span>\nLogon failed, use ctrl+c to cancel basic credential prompt.\nUsername for 'https:\/\/github.com': bullyrooks\nPassword for 'https:\/\/bullyrooks@github.com':\nEnumerating objects: 28, done.\nCounting objects: 100% (28\/28), done.\nDelta compression using up to 4 threads\nCompressing objects: 100% (17\/17), done.\nWriting objects: 100% (26\/26), 52.49 KiB | 8.75 MiB\/s, done.\nTotal 26 (delta 1), reused 0 (delta 0), pack-reused 0\nremote: Resolving deltas: 100% (1\/1), completed with 1 local object.\nremote:\nremote: Create a pull request for 'initial' on GitHub by visiting:\nremote:      https:\/\/github.com\/bullyrooks\/helloworld-lambda\/pull\/new\/initial\nremote:\nTo https:\/\/github.com\/bullyrooks\/helloworld-lambda.git\n * &#91;new branch]      initial -&gt; initial\nBranch 'initial' set up to track remote branch 'initial' from 'origin'.<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Merge to Main<\/h2>\n\n\n\n<p>we already know this works, so lets merge to main for now so we can branch off main for our next session<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><span class=\"has-inline-color has-vivid-red-color\">$ git checkout main<\/span>\r\nSwitched to branch 'main'\r\nYour branch is up to date with 'origin\/main'.\n\n<span class=\"has-inline-color has-vivid-red-color\">$ git merge initial<\/span>\r\nUpdating 629e815..82c760e\r\nFast-forward\r\n\n\r<span class=\"has-inline-color has-vivid-red-color\">$ git push<\/span>\n<\/code><\/pre>\n\n\n\n<p>That&#8217;s it for the setup.  Next we&#8217;re going to build a jar that can be deployed as a lambda.  <\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"entry-summary\">\nIn this course we&#8217;re going to build a very simple spring boot&hellip;\n<\/div>\n<div class=\"link-more\"><a href=\"https:\/\/bullyrooks.com\/index.php\/2021\/07\/23\/spring-boot-lambda-prerequisites\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &ldquo;Spring Boot Lambda Prerequisites&rdquo;<\/span>&hellip;<\/a><\/div>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[41],"tags":[142,144,143,50,42,43],"course":[141],"class_list":["post-1065","post","type-post","status-publish","format-standard","hentry","category-software-development","tag-aws","tag-java","tag-lambda","tag-maven","tag-spring","tag-spring-boot","course-spring-boot-lambda-on-aws","entry"],"jetpack_featured_media_url":"","jetpack-related-posts":[{"id":1115,"url":"https:\/\/bullyrooks.com\/index.php\/2021\/07\/24\/automated-terraform-deploy-using-github-actions\/","url_meta":{"origin":1065,"position":0},"title":"Automated Terraform Deploy Using Github Actions","author":"Bullyrook","date":"July 24, 2021","format":false,"excerpt":"Now we just need to build and deploy our application automatically so that whenever we push changes to the main branch, they'll automatically become available through our endpoint. Create Our Artifact Storage We're going to use a 'poor man's artifactory' to store our compiled .jar files. With our current build\u2026","rel":"","context":"In &quot;Software Development&quot;","block_context":{"text":"Software Development","link":"https:\/\/bullyrooks.com\/index.php\/category\/software-development\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/bullyrooks.com\/wp-content\/uploads\/2021\/07\/image-34.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":1102,"url":"https:\/\/bullyrooks.com\/index.php\/2021\/07\/24\/terraform-centralized-state-management\/","url_meta":{"origin":1065,"position":1},"title":"Terraform Centralized State Management","author":"Bullyrook","date":"July 24, 2021","format":false,"excerpt":"As we saw in the last course Terraform will manage the state of your application, but by default it stores this locally. This is not ideal for us and will cause problems when we try to work with others or create a continuous deployment pipeline. Now we'll create a way\u2026","rel":"","context":"In &quot;Software Development&quot;","block_context":{"text":"Software Development","link":"https:\/\/bullyrooks.com\/index.php\/category\/software-development\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/bullyrooks.com\/wp-content\/uploads\/2021\/07\/image-23.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/bullyrooks.com\/wp-content\/uploads\/2021\/07\/image-23.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/bullyrooks.com\/wp-content\/uploads\/2021\/07\/image-23.png?resize=700%2C400&ssl=1 2x, https:\/\/i0.wp.com\/bullyrooks.com\/wp-content\/uploads\/2021\/07\/image-23.png?resize=1050%2C600&ssl=1 3x, https:\/\/i0.wp.com\/bullyrooks.com\/wp-content\/uploads\/2021\/07\/image-23.png?resize=1400%2C800&ssl=1 4x"},"classes":[]},{"id":1133,"url":"https:\/\/bullyrooks.com\/index.php\/2021\/07\/25\/confirming-the-continuous-deployment-pipeline\/","url_meta":{"origin":1065,"position":2},"title":"Confirming the Continuous Deployment Pipeline","author":"Bullyrook","date":"July 25, 2021","format":false,"excerpt":"Lets verify that changes to our application will be automatically available when they're pushed up. Update the Application Let's start a new branch $ git checkout -b \"greeting-change\" Now update our service to return a different greeting: @Component public class HelloWorldService { public HelloWorld helloWorld(String name) { return HelloWorld.builder() .response(\"G'Day,\u2026","rel":"","context":"In &quot;Software Development&quot;","block_context":{"text":"Software Development","link":"https:\/\/bullyrooks.com\/index.php\/category\/software-development\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/bullyrooks.com\/wp-content\/uploads\/2021\/07\/image-48.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/bullyrooks.com\/wp-content\/uploads\/2021\/07\/image-48.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/bullyrooks.com\/wp-content\/uploads\/2021\/07\/image-48.png?resize=700%2C400&ssl=1 2x, https:\/\/i0.wp.com\/bullyrooks.com\/wp-content\/uploads\/2021\/07\/image-48.png?resize=1050%2C600&ssl=1 3x"},"classes":[]},{"id":1081,"url":"https:\/\/bullyrooks.com\/index.php\/2021\/07\/24\/spring-boot-lambda-api-implementation\/","url_meta":{"origin":1065,"position":3},"title":"Spring Boot Lambda API Implementation","author":"Bullyrook","date":"July 24, 2021","format":false,"excerpt":"We've got a 'working' lambda now, but we can't actually use it anywhere. The easiest thing to do at this point is add an API Gateway trigger to our function as a new lambda. This will require a little bit of work to make an API Gateway adapter to our\u2026","rel":"","context":"In &quot;Software Development&quot;","block_context":{"text":"Software Development","link":"https:\/\/bullyrooks.com\/index.php\/category\/software-development\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/bullyrooks.com\/wp-content\/uploads\/2021\/07\/image-10.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/bullyrooks.com\/wp-content\/uploads\/2021\/07\/image-10.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/bullyrooks.com\/wp-content\/uploads\/2021\/07\/image-10.png?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":1069,"url":"https:\/\/bullyrooks.com\/index.php\/2021\/07\/23\/spring-boot-lambda-implementation\/","url_meta":{"origin":1065,"position":4},"title":"Spring Boot Lambda Implementation","author":"Bullyrook","date":"July 23, 2021","format":false,"excerpt":"Now we're going to add some code. I'm going to follow my ports and adapters method of building a DTO and value object that I've used previously. Yes, its a bit of overkill for this project (especially a hello world example), but if you're using this course as a springboard\u2026","rel":"","context":"In &quot;Software Development&quot;","block_context":{"text":"Software Development","link":"https:\/\/bullyrooks.com\/index.php\/category\/software-development\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/bullyrooks.com\/wp-content\/uploads\/2021\/07\/image-4.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/bullyrooks.com\/wp-content\/uploads\/2021\/07\/image-4.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/bullyrooks.com\/wp-content\/uploads\/2021\/07\/image-4.png?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":1094,"url":"https:\/\/bullyrooks.com\/index.php\/2021\/07\/24\/terraform-setup-and-first-install\/","url_meta":{"origin":1065,"position":5},"title":"Terraform Setup and First Install","author":"Bullyrook","date":"July 24, 2021","format":false,"excerpt":"Terraform is a system that allows you to define your infrastructure in a series of configuration files. These configuration files are linked to a provider library which will execute the infrastructure create, update and teardown commands on the platform you want to deploy to. This is called \"Infrastructure as Code\"\u2026","rel":"","context":"In &quot;Software Development&quot;","block_context":{"text":"Software Development","link":"https:\/\/bullyrooks.com\/index.php\/category\/software-development\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/bullyrooks.com\/wp-content\/uploads\/2021\/07\/image-19.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/bullyrooks.com\/wp-content\/uploads\/2021\/07\/image-19.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/bullyrooks.com\/wp-content\/uploads\/2021\/07\/image-19.png?resize=700%2C400&ssl=1 2x, https:\/\/i0.wp.com\/bullyrooks.com\/wp-content\/uploads\/2021\/07\/image-19.png?resize=1050%2C600&ssl=1 3x"},"classes":[]}],"_links":{"self":[{"href":"https:\/\/bullyrooks.com\/index.php\/wp-json\/wp\/v2\/posts\/1065","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/bullyrooks.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bullyrooks.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bullyrooks.com\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/bullyrooks.com\/index.php\/wp-json\/wp\/v2\/comments?post=1065"}],"version-history":[{"count":2,"href":"https:\/\/bullyrooks.com\/index.php\/wp-json\/wp\/v2\/posts\/1065\/revisions"}],"predecessor-version":[{"id":1071,"href":"https:\/\/bullyrooks.com\/index.php\/wp-json\/wp\/v2\/posts\/1065\/revisions\/1071"}],"wp:attachment":[{"href":"https:\/\/bullyrooks.com\/index.php\/wp-json\/wp\/v2\/media?parent=1065"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bullyrooks.com\/index.php\/wp-json\/wp\/v2\/categories?post=1065"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bullyrooks.com\/index.php\/wp-json\/wp\/v2\/tags?post=1065"},{"taxonomy":"course","embeddable":true,"href":"https:\/\/bullyrooks.com\/index.php\/wp-json\/wp\/v2\/course?post=1065"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}