{"id":26694,"date":"2022-09-16T09:42:00","date_gmt":"2022-09-16T04:12:00","guid":{"rendered":"https:\/\/mobisoftinfotech.com\/resources\/?p=26694"},"modified":"2025-04-30T15:29:21","modified_gmt":"2025-04-30T09:59:21","slug":"how-to-create-rest-api-using-aws-sam-cli-and-java-with-cors-support","status":"publish","type":"post","link":"https:\/\/mobisoftinfotech.com\/resources\/blog\/how-to-create-rest-api-using-aws-sam-cli-and-java-with-cors-support","title":{"rendered":"How to create REST API using AWS SAM CLI and Java with CORS support"},"content":{"rendered":"<p>AWS SAM stands for AWS Serverless Application Model. It is created by AWS to make deployment of AWS Lambda functions easier. With AWS SAM you can describe your serverless application as a YAML file. Then using AWS SAM CLI, you can use this YAML file to deploy all the necessary AWS resources required by your application. Under the hood, AWS SAM CLI generates a Cloud Formation template, which is then used to create and modify the resources required for the application.<\/p>\n\n\n\n<p>In this article we will see how to create a REST API using AWS SAM CLI using the Java programming language. There are some tutorials on the web which show this, however these tutorials don&#8217;t show how to handle some common aspects such as CORS implementation. Recently I had to deploy a quick API using AWS SAM and Java, however, I couldn&#8217;t find an easy to follow tutorial on how to handle CORS implementation with this. After doing some trial and error with some Stack Overflow answers, I managed to get it to work properly. Hence I thought it&#8217;s better to write a tutorial to cover CORS implementation also along with a basic REST API. So let&#8217;s get started.<\/p>\n\n\n\n<p>Before starting you will need to ensure that you have <a href=\"https:\/\/docs.aws.amazon.com\/cli\/latest\/userguide\/cli-chap-welcome.html\">AWS CLI<\/a>, <a href=\"https:\/\/docs.aws.amazon.com\/serverless-application-model\/latest\/developerguide\/serverless-sam-cli-install.html\">AWS SAM CLI<\/a> and <a href=\"https:\/\/adoptium.net\/\">JDK<\/a> installed and configured on your system. For this tutorial I am using JDK 11. As of September 2022, it seems that AWS Lambda doesn&#8217;t support JDK 17 runtime. This may change in future. If you want to test your API locally, you will also need <a href=\"https:\/\/www.docker.com\/products\/docker-desktop\/\">Docker Desktop <\/a>installed. Also ensure that you have <a href=\"https:\/\/docs.aws.amazon.com\/cli\/latest\/userguide\/cli-configure-quickstart.html\">an AWS account configured<\/a> to use with your AWS CLI using the aws configure command.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Source Code<\/h2>\n\n\n\n<p class=\"has-text-align-left\">You can find the complete source code for this tutorial here: <a href=\"https:\/\/github.com\/MobisoftInfotech\/java-sam-api-example\">https:\/\/github.com\/MobisoftInfotech\/java-sam-api-example<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Generate Application Skeleton using AWS SAM CLI<\/h2>\n\n\n\n<p>Once all the required software is installed, you can generate a java based AWS SAM application using the following command:<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">sam init -r java11 -d maven --app-template hello-world -n java-sam-api-example<\/code><\/span><\/pre>\n\n\n<p>This will create a directory named java-sam-api-example and will generate the initial sources. It generates following files:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css\"><span class=\"hljs-selector-tag\">java-sam-api-example<\/span>\n\u251c\u2500\u2500 <span class=\"hljs-selector-tag\">HelloWorldFunction<\/span>\n\u2502   \u251c\u2500\u2500 <span class=\"hljs-selector-tag\">pom<\/span><span class=\"hljs-selector-class\">.xml<\/span>\n\u2502   \u2514\u2500\u2500 <span class=\"hljs-selector-tag\">src<\/span>\n\u2502       \u251c\u2500\u2500 <span class=\"hljs-selector-tag\">main<\/span>\n\u2502       \u2502   \u2514\u2500\u2500 <span class=\"hljs-selector-tag\">java<\/span>\n\u2502       \u2502       \u2514\u2500\u2500 <span class=\"hljs-selector-tag\">helloworld<\/span>\n\u2502       \u2502           \u2514\u2500\u2500 <span class=\"hljs-selector-tag\">App<\/span><span class=\"hljs-selector-class\">.java<\/span>\n\u2502       \u2514\u2500\u2500 <span class=\"hljs-selector-tag\">test<\/span>\n\u2502           \u2514\u2500\u2500 <span class=\"hljs-selector-tag\">java<\/span>\n\u2502               \u2514\u2500\u2500 <span class=\"hljs-selector-tag\">helloworld<\/span>\n\u2502                   \u2514\u2500\u2500 <span class=\"hljs-selector-tag\">AppTest<\/span><span class=\"hljs-selector-class\">.java<\/span>\n\u251c\u2500\u2500 <span class=\"hljs-selector-tag\">README<\/span><span class=\"hljs-selector-class\">.md<\/span>\n\u251c\u2500\u2500 <span class=\"hljs-selector-tag\">events<\/span>\n\u2502   \u2514\u2500\u2500 <span class=\"hljs-selector-tag\">event<\/span><span class=\"hljs-selector-class\">.json<\/span>\n\u2514\u2500\u2500 <span class=\"hljs-selector-tag\">template<\/span><span class=\"hljs-selector-class\">.yaml<\/span>\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Unfortunately SAM CLI hardcodes the word &#8220;hello world&#8221; all over your code. So you need to manually change it everywhere. So I did that as per our application&#8217;s needs and this is how it looks after the changes:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css\"><span class=\"hljs-selector-tag\">java-sam-api-example<\/span>\n\u251c\u2500\u2500 <span class=\"hljs-selector-tag\">README<\/span><span class=\"hljs-selector-class\">.md<\/span>\n\u251c\u2500\u2500 <span class=\"hljs-selector-tag\">SAMExampleFunction<\/span>\n\u2502   \u251c\u2500\u2500 <span class=\"hljs-selector-tag\">pom<\/span><span class=\"hljs-selector-class\">.xml<\/span>\n\u2502   \u2514\u2500\u2500 <span class=\"hljs-selector-tag\">src<\/span>\n\u2502       \u251c\u2500\u2500 <span class=\"hljs-selector-tag\">main<\/span>\n\u2502       \u2502   \u2514\u2500\u2500 <span class=\"hljs-selector-tag\">java<\/span>\n\u2502       \u2502       \u2514\u2500\u2500 <span class=\"hljs-selector-tag\">samexample<\/span>\n\u2502       \u2502           \u2514\u2500\u2500 <span class=\"hljs-selector-tag\">App<\/span><span class=\"hljs-selector-class\">.java<\/span>\n\u2502       \u2514\u2500\u2500 <span class=\"hljs-selector-tag\">test<\/span>\n\u2502           \u2514\u2500\u2500 <span class=\"hljs-selector-tag\">java<\/span>\n\u2502               \u2514\u2500\u2500 <span class=\"hljs-selector-tag\">samexample<\/span>\n\u2502                   \u2514\u2500\u2500 <span class=\"hljs-selector-tag\">AppTest<\/span><span class=\"hljs-selector-class\">.java<\/span>\n\u251c\u2500\u2500 <span class=\"hljs-selector-tag\">events<\/span>\n\u2502   \u2514\u2500\u2500 <span class=\"hljs-selector-tag\">event<\/span><span class=\"hljs-selector-class\">.json<\/span>\n\u2514\u2500\u2500 <span class=\"hljs-selector-tag\">template<\/span><span class=\"hljs-selector-class\">.yaml<\/span>\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>I have renamed the &#8220;HelloWorldFunction&#8221; directory to &#8220;SAMExampleFunction&#8221; and also changed package name from helloworld to &#8220;samexample&#8221;. Of course you should use a name relevant to your project here.<\/p>\n\n\n\n<p>Here since we have changed the package name to &#8220;samexample&#8221;, we will need to change the &#8220;App.java&#8221; and &#8220;AppTest.java&#8221; files also to change the package line from:<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">package helloworld;<\/code><\/span><\/pre>\n\n\n<p>to:<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">package samexample;<\/code><\/span><\/pre>\n\n\n<p>One of the most important files here is the <span class=\"inline-code\">template.yaml<\/span>. It describes the serverless application. Again unfortunately SAM CLI hard codes the word &#8220;hello world&#8221; everywhere in this template. So let&#8217;s first modify this as per our needs so that it looks like the following:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">AWSTemplateFormatVersion: '2010-09-09'\nTransform: AWS::Serverless-2016-10-31\nDescription: &gt;\n  java-sam-api-example\n\n  Sample SAM Template for java-sam-api-example\n\nGlobals:\n  Function:\n    Timeout: 20\n\nResources:\n  SAMExampleFunction:\n    Type: AWS::Serverless::Function \n    Properties:\n      CodeUri: SAMExampleFunction\n      Handler: samexample.App::handleRequest\n      Runtime: java11\n      Architectures:\n        - x86_64\n      MemorySize: 512\n      Environment: \n        Variables:\n          PARAM1: VALUE\n          JAVA_TOOL_OPTIONS: -XX:+TieredCompilation -XX:TieredStopAtLevel=1\n      Events:\n        SAMExample:\n          Type: Api \n          Properties:\n            Path: \/hello\n            Method: get\n\nOutputs:\n  SAMExampleApi:\n    Description: \"API Gateway endpoint URL for Prod stage for Hello World function\"\n    Value: !Sub \"https:\/\/${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com\/Prod\/hello\/\"\n  SAMExampleFunction:\n    Description: \"Hello World Lambda Function ARN\"\n    Value: !GetAtt SAMExampleFunction.Arn\n  SAMExampleFunctionIamRole:\n    Description: \"Implicit IAM Role created for Hello World function\"\n    Value: !GetAtt SAMExampleFunctionRole.Arn\n<\/pre>\n\n\n\n<p>At this point you can build and run the application locally using the commands:<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">sam build\nsam local start-api<\/code><\/span><\/pre>\n\n\n<p>Now of you test the API using following command:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">curl --location --request GET <span class=\"hljs-string\">'http:\/\/127.0.0.1:3000\/hello'<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>You should see following output:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"JSON \/ JSON with Comments\" data-shcb-language-slug=\"json\"><span><code class=\"hljs language-json\">{ <span class=\"hljs-attr\">\"message\"<\/span>: <span class=\"hljs-string\">\"hello world\"<\/span>, <span class=\"hljs-attr\">\"location\"<\/span>: <span class=\"hljs-string\">\"103.254.55.17\"<\/span> }<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JSON \/ JSON with Comments<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">json<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>As you may already know, to expose a lambda function as HTTP endpoint, you need AWS API Gateway to be configured. In this &#8220;hello world&#8221; template, it uses an implicit gateway resource named: <span class=\"inline-code\">ServerlessRestApi<\/span>. As it turns out to support CORS you need to modify the API gateway resource. So we can&#8217;t use this implicit API gateway resource. So we will create a API resource in our template.yaml file:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">AWSTemplateFormatVersion: '2010-09-09'\nTransform: AWS::Serverless-2016-10-31\nDescription: &gt;\n java-sam-api-example\n\n Sample SAM Template for java-sam-api-example\n\nGlobals:\n Function:\n   Timeout: 20\n\nResources:\n SAMExampleApi:\n   Type: AWS::Serverless::Api\n   Properties:\n     StageName: Prod\n     Cors:\n       AllowMethods: \"'GET,POST,OPTIONS,PUT,PATCH,DELETE'\"\n       AllowHeaders: \"'content-type'\"\n       AllowOrigin: \"'*'\"\n       AllowCredentials: \"'*'\"\n SAMExampleFunction:\n   Type: AWS::Serverless::Function\n   Properties:\n     CodeUri: SAMExampleFunction\n     Handler: samexample.App::handleRequest\n     Runtime: java11\n     Architectures:\n       - x86_64\n     MemorySize: 512\n     Environment:\n       Variables:\n         PARAM1: VALUE\n         JAVA_TOOL_OPTIONS: -XX:+TieredCompilation -XX:TieredStopAtLevel=1\n     Events:\n       SAMExample:\n         Type: Api\n         Properties:\n           Path: \/hello\n           Method: get\n           RestApiId: !Ref SAMExampleApi\n\nOutputs:\n SAMExampleApi:\n   Description: \"API Gateway endpoint URL for Prod stage for Hello World function\"\n   Value: !Sub \"https:\/\/${SAMExampleApi}.execute-api.${AWS::Region}.amazonaws.com\/Prod\/hello\/\"\n SAMExampleFunction:\n   Description: \"Hello World Lambda Function ARN\"\n   Value: !GetAtt SAMExampleFunction.Arn\n SAMExampleFunctionIamRole:\n   Description: \"Implicit IAM Role created for Hello World function\"\n   Value: !GetAtt SAMExampleFunctionRole.Arn\n<\/pre>\n\n\n\n<p>Here as you can notice we have added a new resource:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"> SAMExampleApi:\n   Type: AWS::Serverless::Api\n   Properties:\n     StageName: Prod\n     Cors:\n       AllowMethods: \"'GET,POST,OPTIONS,PUT,PATCH,DELETE'\"\n       AllowHeaders: \"'content-type,X-Custom-Header'\"\n       AllowOrigin: \"'*'\"\n       AllowCredentials: \"'*'\"\n<\/pre>\n\n\n\n<p>Here I am using all HTTP methods in the <span class=\"inline-code\"> &#8220;AllowMethods&#8221; <\/span> and allowing &#8220;*&#8221; (any) origin in the &#8220;AllowOrigin&#8221; header. However for production deployments you should restrict the HTTP methods to the methods your API supports and the origin to your &#8220;production&#8221; domain only. In the AllowHeaders, you need to mention all the custom headers your API supports.<\/p>\n\n\n\n<p>Then in the Events under &#8220;SAMExampleFunction&#8221; we have added new line:<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\"> RestApiId: !Ref SAMExampleApi<\/code><\/span><\/pre>\n\n\n<p>Also in the &#8220;Outputs&#8221; section we have updated the &#8220;Value&#8221; for the &#8220;SAMExampleApi&#8221; like follows:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-5\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\"> Value: !Sub <span class=\"hljs-string\">\"https:\/\/${SAMExampleApi}.execute-api.${AWS::Region}.amazonaws.com\/Prod\/hello\/\"<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-5\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>To support CORS we will need to make some changes to our Java code also. So we need to add the following lines in the <span class=\"inline-code\">&#8220;handleReuest&#8221; <\/span> method of the App.java file:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-6\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">headers.put(<span class=\"hljs-string\">\"Access-Control-Allow-Origin\"<\/span>, <span class=\"hljs-string\">\"*\"<\/span>);\nheaders.put(<span class=\"hljs-string\">\"Access-Control-Allow-Methods\"<\/span>, <span class=\"hljs-string\">\"GET,POST,OPTIONS,PUT,PATCH,DELETE\"<\/span>);\nheaders.put(<span class=\"hljs-string\">\"Access-Control-Allow-Headers\"<\/span>, <span class=\"hljs-string\">\"content-type,X-Custom-Header\"<\/span>);<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-6\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>just below the line:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-7\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">headers.put(<span class=\"hljs-string\">\"X-Custom-Header\"<\/span>, <span class=\"hljs-string\">\"application\/json\"<\/span>);<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-7\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>At this point we are ready to deploy our application so let&#8217;s run the following commands:<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">sam build\nsam deploy --guided<\/code><\/span><\/pre>\n\n\n<p>At this point SAM CLI will ask you a bunch of questions about how to deploy your serverless application. Here are the answers I provided:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-8\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\">Setting <span class=\"hljs-keyword\">default<\/span> arguments <span class=\"hljs-keyword\">for<\/span> <span class=\"hljs-string\">'sam deploy'<\/span>\n=========================================\nStack Name &#091;sam-app]: java-sam-api-example   \nAWS Region &#091;us-west<span class=\"hljs-number\">-2<\/span>]:\n<span class=\"hljs-comment\">#Shows you resources changes to be deployed and require a 'Y' to initiate deploy<\/span>\nConfirm changes before deploy &#091;y\/N]: y\n<span class=\"hljs-comment\">#SAM needs permission to be able to create roles to connect to the resources in your template<\/span>\nAllow SAM CLI IAM role creation &#091;Y\/n]: Y\n<span class=\"hljs-comment\">#Preserves the state of previously provisioned resources when an operation fails<\/span>\nDisable rollback &#091;y\/N]: N\nSAMExampleFunction may not have authorization defined, Is this okay? &#091;y\/N]: y\nSave arguments to configuration file &#091;Y\/n]: Y\nSAM configuration file &#091;samconfig.toml]:\nSAM configuration environment &#091;<span class=\"hljs-keyword\">default<\/span>]:\n\n\u2026\n\u2026\n\nPreviewing CloudFormation changeset before deployment\n======================================================\nDeploy this changeset? &#091;y\/N]: Y<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-8\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Now SAM CLI will generate the CloudFormation template and will deploy a CloudFormation stack for the same. Once the deployment is complete, you should see the output similar to the following:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-9\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">Outputs                                                                                              \n------------------------------------------------------------------------------------------------------\nKey                 SAMExampleFunctionIamRole                                                        \nDescription         Implicit IAM Role created <span class=\"hljs-keyword\">for<\/span> Hello World <span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span>                               \n<span class=\"hljs-title\">Value<\/span>               <span class=\"hljs-title\">arn<\/span>:<span class=\"hljs-title\">aws<\/span>:<span class=\"hljs-title\">iam<\/span>::615447684439:<span class=\"hljs-title\">role<\/span>\/<span class=\"hljs-title\">java<\/span>-<span class=\"hljs-title\">sam<\/span>-<span class=\"hljs-title\">api<\/span>-<span class=\"hljs-title\">example<\/span>-<span class=\"hljs-title\">SAMExampleFunctionRole<\/span>-      \n<span class=\"hljs-title\">WKAFDXI4UXXG<\/span>                                                                                         \n\n<span class=\"hljs-title\">Key<\/span>                 <span class=\"hljs-title\">SAMExampleApi<\/span>                                                                    \n<span class=\"hljs-title\">Description<\/span>         <span class=\"hljs-title\">API<\/span> <span class=\"hljs-title\">Gateway<\/span> <span class=\"hljs-title\">endpoint<\/span> <span class=\"hljs-title\">URL<\/span> <span class=\"hljs-title\">for<\/span> <span class=\"hljs-title\">Prod<\/span> <span class=\"hljs-title\">stage<\/span> <span class=\"hljs-title\">for<\/span> <span class=\"hljs-title\">Hello<\/span> <span class=\"hljs-title\">World<\/span> <span class=\"hljs-title\">function<\/span>                 \n<span class=\"hljs-title\">Value<\/span>               <span class=\"hljs-title\">https<\/span>:\/\/572<span class=\"hljs-title\">qk46wc9<\/span>.<span class=\"hljs-title\">execute<\/span>-<span class=\"hljs-title\">api<\/span>.<span class=\"hljs-title\">us<\/span>-<span class=\"hljs-title\">west<\/span>-2.<span class=\"hljs-title\">amazonaws<\/span>.<span class=\"hljs-title\">com<\/span>\/<span class=\"hljs-title\">Prod<\/span>\/<span class=\"hljs-title\">hello<\/span>\/               \n\n<span class=\"hljs-title\">Key<\/span>                 <span class=\"hljs-title\">SAMExampleFunction<\/span>                                                               \n<span class=\"hljs-title\">Description<\/span>         <span class=\"hljs-title\">Hello<\/span> <span class=\"hljs-title\">World<\/span> <span class=\"hljs-title\">Lambda<\/span> <span class=\"hljs-title\">Function<\/span> <span class=\"hljs-title\">ARN<\/span>                                                  \n<span class=\"hljs-title\">Value<\/span>               <span class=\"hljs-title\">arn<\/span>:<span class=\"hljs-title\">aws<\/span>:<span class=\"hljs-title\">lambda<\/span>:<span class=\"hljs-title\">us<\/span>-<span class=\"hljs-title\">west<\/span>-2:615447684439:<span class=\"hljs-title\">function<\/span>:<span class=\"hljs-title\">java<\/span>-<span class=\"hljs-title\">sam<\/span>-<span class=\"hljs-title\">api<\/span>-<span class=\"hljs-title\">example<\/span>-             \n<span class=\"hljs-title\">SAMExampleFunction<\/span>-<span class=\"hljs-title\">T19RPWh6SzlB<\/span>                                                                      \n------------------------------------------------------------------------------------------------------\n<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-9\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>From the output you can get the URL for your API.<\/p>\n\n\n\n<p>You can create a quick local file &#8216;index.html&#8217; with the following content to ensure that your API indeed supports CORS properly:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&lt;script&gt;\nconst requestOptions = {\n   method: 'GET',\n   headers: { 'Content-Type': 'application\/json' }\n};\nfetch('https:\/\/572qk46wc9.execute-api.us-west-2.amazonaws.com\/Prod\/hello\/', requestOptions)\n   .then(response =&gt; console.log(response))\n   .catch(err =&gt; console.log(err));\n&lt;\/script&gt;\n<\/pre>\n\n\n\n<p>You can use any local static file server like Apache, Nginx to access this index.html file locally. I use a NPM package called &#8220;serve&#8221; for this purpose. You can install it with the command<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">npm install -g serve<\/code><\/span><\/pre>\n\n\n<p>Then in any directory you can run the command &#8220;serve&#8221; to serve that directory on <span class=\"inline-code\">localhost:3000<\/span> by default. When I do this and open the URL <span class=\"inline-code\">http:\/\/localhost:3000\/<\/span> in the browser, I see in the browser console that the API call succeeds and the CORS is working properly.<\/p>\n\n\n\n<p>So that&#8217;s how we can create a Serverless Java API with AWS SAM CLI with CORS support. Now to destroy all the resources we created we can run the command:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-10\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">sam <span class=\"hljs-keyword\">delete<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-10\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>It will ask you to confirm the deletion and once confirmed will destroy all the resources created on AWS.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/mobisoftinfotech.com\/contact-us?utm_source=blog&amp;utm_medium=how-to-create-rest-api-using-aws-sam-cli-and-java-with-cors-support-cta1 \"><noscript><img decoding=\"async\" width=\"800\" height=\"340\" src=\"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/03\/cta2.jpg\" alt class=\"wp-image-37688\"><\/noscript><img decoding=\"async\" width=\"800\" height=\"340\" src=\"data:image\/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20800%20340%22%3E%3C%2Fsvg%3E\" alt class=\"wp-image-37688 lazyload\" data-src=\"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/03\/cta2.jpg\"><\/a><\/figure>\n\n\n<div class=\"modern-author-card\">\n    <div class=\"author-card-content\">\n        <div class=\"author-info-section\">\n            <div class=\"author-avatar\">\n                <noscript><img decoding=\"async\" src=\"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2022\/04\/Pritam1.jpg\" alt=\"Pritam Barhate\"><\/noscript><img decoding=\"async\" src=\"data:image\/gif;base64,R0lGODlhAQABAIAAAAAAAP\/\/\/yH5BAEAAAAALAAAAAABAAEAAAIBRAA7\" alt=\"Pritam Barhate\" data-src=\"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2022\/04\/Pritam1.jpg\" class=\" lazyload\">\n            <\/div>\n            <div class=\"author-details\">\n                <h3 class=\"author-name\">Pritam Barhate<\/h3>\n                <p class=\"author-title\">Head of Technology Innovation<\/p>\n                <a href=\"javascript:void(0);\" class=\"read-more-link read-more-btn\" onclick=\"toggleAuthorBio(this); return false;\">Read more <noscript><img decoding=\"async\" src=\"\/assets\/images\/blog\/Vector.png\" alt=\"expand\" class=\"read-more-arrow down-arrow\"><\/noscript><img decoding=\"async\" src=\"data:image\/gif;base64,R0lGODlhAQABAIAAAAAAAP\/\/\/yH5BAEAAAAALAAAAAABAAEAAAIBRAA7\" alt=\"expand\" class=\"read-more-arrow down-arrow lazyload\" data-src=\"\/assets\/images\/blog\/Vector.png\"><\/a>\n                <div class=\"author-bio-expanded\">\n                    <p>Pritam Barhate, with an experience of 14+ years in technology, heads Technology Innovation at <a href=\"https:\/\/mobisoftinfotech.com\" target=\"_blank\" rel=\"noopener\">Mobisoft Infotech<\/a>. He has a rich experience in design and development. He has been a consultant for a variety of industries and startups. At Mobisoft Infotech, he primarily focuses on technology resources and develops the most advanced solutions.<\/p>\n                    <div class=\"author-social-links\">\n                        <div class=\"social-icon\">\n                            <a href=\"https:\/\/www.linkedin.com\/in\/pritam-barhate-90b93414\/\" target=\"_blank\" rel=\"nofollow noopener\"><i class=\"icon-sprite linkedin\"><\/i><\/a>\n                            <a href=\"https:\/\/twitter.com\/pritambarhate\" target=\"_blank\" rel=\"nofollow noopener\"><i class=\"icon-sprite twitter\"><\/i><\/a>\n                        <\/div>\n                    <\/div>\n                    <a href=\"javascript:void(0);\" class=\"read-more-link read-less-btn\" onclick=\"toggleAuthorBio(this); return false;\" style=\"display: none;\">Read less <noscript><img decoding=\"async\" src=\"\/assets\/images\/blog\/Vector.png\" alt=\"collapse\" class=\"read-more-arrow up-arrow\"><\/noscript><img decoding=\"async\" src=\"data:image\/gif;base64,R0lGODlhAQABAIAAAAAAAP\/\/\/yH5BAEAAAAALAAAAAABAAEAAAIBRAA7\" alt=\"collapse\" class=\"read-more-arrow up-arrow lazyload\" data-src=\"\/assets\/images\/blog\/Vector.png\"><\/a>\n                <\/div>\n            <\/div>\n        <\/div>\n        <div class=\"share-section\">\n            <span class=\"share-label\">Share Article<\/span>\n            <div class=\"social-share-buttons\">\n                <a href=\"https:\/\/www.facebook.com\/sharer\/sharer.php?u=https%3A%2F%2Fmobisoftinfotech.com%2Fresources%2Fblog%2Fhow-to-create-rest-api-using-aws-sam-cli-and-java-with-cors-support\" target=\"_blank\" class=\"share-btn facebook-share\"><i class=\"fa fa-facebook-f\"><\/i><\/a>\n                <a href=\"https:\/\/www.linkedin.com\/sharing\/share-offsite\/?url=https%3A%2F%2Fmobisoftinfotech.com%2Fresources%2Fblog%2Fhow-to-create-rest-api-using-aws-sam-cli-and-java-with-cors-support\" target=\"_blank\" class=\"share-btn linkedin-share\"><i class=\"fa fa-linkedin\"><\/i><\/a>\n            <\/div>\n        <\/div>\n    <\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>AWS SAM stands for AWS Serverless Application Model. It is created by AWS to make deployment of AWS Lambda functions easier. With AWS SAM you can describe your serverless application as a YAML file. Then using AWS SAM CLI, you can use this YAML file to deploy all the necessary AWS resources required by your [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":26711,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_s2mail":"","footnotes":""},"categories":[286],"tags":[772,3280,3282,3283,3279,3281],"class_list":["post-26694","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog","tag-aws","tag-java","tag-lambda","tag-rest-api","tag-sam-cli","tag-serverless"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.2 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to create REST API using AWS SAM CLI and Java with CORS support<\/title>\n<meta name=\"description\" content=\"Tutorial on creation of REST API using AWS Lambda using Java with CORS support.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/mobisoftinfotech.com\/resources\/blog\/how-to-create-rest-api-using-aws-sam-cli-and-java-with-cors-support\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to create REST API using AWS SAM CLI and Java with CORS support\" \/>\n<meta property=\"og:description\" content=\"Tutorial on creation of REST API using AWS Lambda using Java with CORS support.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/mobisoftinfotech.com\/resources\/blog\/how-to-create-rest-api-using-aws-sam-cli-and-java-with-cors-support\" \/>\n<meta property=\"og:site_name\" content=\"Mobisoft Infotech\" \/>\n<meta property=\"article:published_time\" content=\"2022-09-16T04:12:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-04-30T09:59:21+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2022\/09\/og.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1000\" \/>\n\t<meta property=\"og:image:height\" content=\"525\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Pritam Barhate\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:image\" content=\"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2022\/09\/og.png\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Pritam Barhate\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/mobisoftinfotech.com\/resources\/blog\/how-to-create-rest-api-using-aws-sam-cli-and-java-with-cors-support#article\",\"isPartOf\":{\"@id\":\"https:\/\/mobisoftinfotech.com\/resources\/blog\/how-to-create-rest-api-using-aws-sam-cli-and-java-with-cors-support\"},\"author\":{\"name\":\"Pritam Barhate\",\"@id\":\"https:\/\/mobisoftinfotech.com\/resources\/#\/schema\/person\/fa762036b3364f26abeea146c01487ee\"},\"headline\":\"How to create REST API using AWS SAM CLI and Java with CORS support\",\"datePublished\":\"2022-09-16T04:12:00+00:00\",\"dateModified\":\"2025-04-30T09:59:21+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/mobisoftinfotech.com\/resources\/blog\/how-to-create-rest-api-using-aws-sam-cli-and-java-with-cors-support\"},\"wordCount\":976,\"image\":{\"@id\":\"https:\/\/mobisoftinfotech.com\/resources\/blog\/how-to-create-rest-api-using-aws-sam-cli-and-java-with-cors-support#primaryimage\"},\"thumbnailUrl\":\"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2022\/09\/Banner.png\",\"keywords\":[\"AWS\",\"Java\",\"Lambda\",\"REST API\",\"SAM CLI\",\"Serverless\"],\"articleSection\":[\"Blog\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/mobisoftinfotech.com\/resources\/blog\/how-to-create-rest-api-using-aws-sam-cli-and-java-with-cors-support\",\"url\":\"https:\/\/mobisoftinfotech.com\/resources\/blog\/how-to-create-rest-api-using-aws-sam-cli-and-java-with-cors-support\",\"name\":\"How to create REST API using AWS SAM CLI and Java with CORS support\",\"isPartOf\":{\"@id\":\"https:\/\/mobisoftinfotech.com\/resources\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/mobisoftinfotech.com\/resources\/blog\/how-to-create-rest-api-using-aws-sam-cli-and-java-with-cors-support#primaryimage\"},\"image\":{\"@id\":\"https:\/\/mobisoftinfotech.com\/resources\/blog\/how-to-create-rest-api-using-aws-sam-cli-and-java-with-cors-support#primaryimage\"},\"thumbnailUrl\":\"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2022\/09\/Banner.png\",\"datePublished\":\"2022-09-16T04:12:00+00:00\",\"dateModified\":\"2025-04-30T09:59:21+00:00\",\"author\":{\"@id\":\"https:\/\/mobisoftinfotech.com\/resources\/#\/schema\/person\/fa762036b3364f26abeea146c01487ee\"},\"description\":\"Tutorial on creation of REST API using AWS Lambda using Java with CORS support.\",\"breadcrumb\":{\"@id\":\"https:\/\/mobisoftinfotech.com\/resources\/blog\/how-to-create-rest-api-using-aws-sam-cli-and-java-with-cors-support#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/mobisoftinfotech.com\/resources\/blog\/how-to-create-rest-api-using-aws-sam-cli-and-java-with-cors-support\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/mobisoftinfotech.com\/resources\/blog\/how-to-create-rest-api-using-aws-sam-cli-and-java-with-cors-support#primaryimage\",\"url\":\"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2022\/09\/Banner.png\",\"contentUrl\":\"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2022\/09\/Banner.png\",\"width\":855,\"height\":392,\"caption\":\"API using AWS SAM and Java\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/mobisoftinfotech.com\/resources\/blog\/how-to-create-rest-api-using-aws-sam-cli-and-java-with-cors-support#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/mobisoftinfotech.com\/resources\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to create REST API using AWS SAM CLI and Java with CORS support\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/mobisoftinfotech.com\/resources\/#website\",\"url\":\"https:\/\/mobisoftinfotech.com\/resources\/\",\"name\":\"Mobisoft Infotech\",\"description\":\"Discover Mobility\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/mobisoftinfotech.com\/resources\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/mobisoftinfotech.com\/resources\/#\/schema\/person\/fa762036b3364f26abeea146c01487ee\",\"name\":\"Pritam Barhate\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/secure.gravatar.com\/avatar\/0e481c7ce54b3567ac70ddfc493523eefce0bdc3ee69fd2654f8f60a79e2f178?s=96&r=g\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/0e481c7ce54b3567ac70ddfc493523eefce0bdc3ee69fd2654f8f60a79e2f178?s=96&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/0e481c7ce54b3567ac70ddfc493523eefce0bdc3ee69fd2654f8f60a79e2f178?s=96&r=g\",\"caption\":\"Pritam Barhate\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to create REST API using AWS SAM CLI and Java with CORS support","description":"Tutorial on creation of REST API using AWS Lambda using Java with CORS support.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/mobisoftinfotech.com\/resources\/blog\/how-to-create-rest-api-using-aws-sam-cli-and-java-with-cors-support","og_locale":"en_US","og_type":"article","og_title":"How to create REST API using AWS SAM CLI and Java with CORS support","og_description":"Tutorial on creation of REST API using AWS Lambda using Java with CORS support.","og_url":"https:\/\/mobisoftinfotech.com\/resources\/blog\/how-to-create-rest-api-using-aws-sam-cli-and-java-with-cors-support","og_site_name":"Mobisoft Infotech","article_published_time":"2022-09-16T04:12:00+00:00","article_modified_time":"2025-04-30T09:59:21+00:00","og_image":[{"width":1000,"height":525,"url":"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2022\/09\/og.png","type":"image\/png"}],"author":"Pritam Barhate","twitter_card":"summary_large_image","twitter_image":"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2022\/09\/og.png","twitter_misc":{"Written by":"Pritam Barhate","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/mobisoftinfotech.com\/resources\/blog\/how-to-create-rest-api-using-aws-sam-cli-and-java-with-cors-support#article","isPartOf":{"@id":"https:\/\/mobisoftinfotech.com\/resources\/blog\/how-to-create-rest-api-using-aws-sam-cli-and-java-with-cors-support"},"author":{"name":"Pritam Barhate","@id":"https:\/\/mobisoftinfotech.com\/resources\/#\/schema\/person\/fa762036b3364f26abeea146c01487ee"},"headline":"How to create REST API using AWS SAM CLI and Java with CORS support","datePublished":"2022-09-16T04:12:00+00:00","dateModified":"2025-04-30T09:59:21+00:00","mainEntityOfPage":{"@id":"https:\/\/mobisoftinfotech.com\/resources\/blog\/how-to-create-rest-api-using-aws-sam-cli-and-java-with-cors-support"},"wordCount":976,"image":{"@id":"https:\/\/mobisoftinfotech.com\/resources\/blog\/how-to-create-rest-api-using-aws-sam-cli-and-java-with-cors-support#primaryimage"},"thumbnailUrl":"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2022\/09\/Banner.png","keywords":["AWS","Java","Lambda","REST API","SAM CLI","Serverless"],"articleSection":["Blog"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/mobisoftinfotech.com\/resources\/blog\/how-to-create-rest-api-using-aws-sam-cli-and-java-with-cors-support","url":"https:\/\/mobisoftinfotech.com\/resources\/blog\/how-to-create-rest-api-using-aws-sam-cli-and-java-with-cors-support","name":"How to create REST API using AWS SAM CLI and Java with CORS support","isPartOf":{"@id":"https:\/\/mobisoftinfotech.com\/resources\/#website"},"primaryImageOfPage":{"@id":"https:\/\/mobisoftinfotech.com\/resources\/blog\/how-to-create-rest-api-using-aws-sam-cli-and-java-with-cors-support#primaryimage"},"image":{"@id":"https:\/\/mobisoftinfotech.com\/resources\/blog\/how-to-create-rest-api-using-aws-sam-cli-and-java-with-cors-support#primaryimage"},"thumbnailUrl":"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2022\/09\/Banner.png","datePublished":"2022-09-16T04:12:00+00:00","dateModified":"2025-04-30T09:59:21+00:00","author":{"@id":"https:\/\/mobisoftinfotech.com\/resources\/#\/schema\/person\/fa762036b3364f26abeea146c01487ee"},"description":"Tutorial on creation of REST API using AWS Lambda using Java with CORS support.","breadcrumb":{"@id":"https:\/\/mobisoftinfotech.com\/resources\/blog\/how-to-create-rest-api-using-aws-sam-cli-and-java-with-cors-support#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/mobisoftinfotech.com\/resources\/blog\/how-to-create-rest-api-using-aws-sam-cli-and-java-with-cors-support"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/mobisoftinfotech.com\/resources\/blog\/how-to-create-rest-api-using-aws-sam-cli-and-java-with-cors-support#primaryimage","url":"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2022\/09\/Banner.png","contentUrl":"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2022\/09\/Banner.png","width":855,"height":392,"caption":"API using AWS SAM and Java"},{"@type":"BreadcrumbList","@id":"https:\/\/mobisoftinfotech.com\/resources\/blog\/how-to-create-rest-api-using-aws-sam-cli-and-java-with-cors-support#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/mobisoftinfotech.com\/resources\/"},{"@type":"ListItem","position":2,"name":"How to create REST API using AWS SAM CLI and Java with CORS support"}]},{"@type":"WebSite","@id":"https:\/\/mobisoftinfotech.com\/resources\/#website","url":"https:\/\/mobisoftinfotech.com\/resources\/","name":"Mobisoft Infotech","description":"Discover Mobility","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/mobisoftinfotech.com\/resources\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/mobisoftinfotech.com\/resources\/#\/schema\/person\/fa762036b3364f26abeea146c01487ee","name":"Pritam Barhate","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/0e481c7ce54b3567ac70ddfc493523eefce0bdc3ee69fd2654f8f60a79e2f178?s=96&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/0e481c7ce54b3567ac70ddfc493523eefce0bdc3ee69fd2654f8f60a79e2f178?s=96&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/0e481c7ce54b3567ac70ddfc493523eefce0bdc3ee69fd2654f8f60a79e2f178?s=96&r=g","caption":"Pritam Barhate"}}]}},"_links":{"self":[{"href":"https:\/\/mobisoftinfotech.com\/resources\/wp-json\/wp\/v2\/posts\/26694","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mobisoftinfotech.com\/resources\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mobisoftinfotech.com\/resources\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mobisoftinfotech.com\/resources\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mobisoftinfotech.com\/resources\/wp-json\/wp\/v2\/comments?post=26694"}],"version-history":[{"count":67,"href":"https:\/\/mobisoftinfotech.com\/resources\/wp-json\/wp\/v2\/posts\/26694\/revisions"}],"predecessor-version":[{"id":37937,"href":"https:\/\/mobisoftinfotech.com\/resources\/wp-json\/wp\/v2\/posts\/26694\/revisions\/37937"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/mobisoftinfotech.com\/resources\/wp-json\/wp\/v2\/media\/26711"}],"wp:attachment":[{"href":"https:\/\/mobisoftinfotech.com\/resources\/wp-json\/wp\/v2\/media?parent=26694"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mobisoftinfotech.com\/resources\/wp-json\/wp\/v2\/categories?post=26694"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mobisoftinfotech.com\/resources\/wp-json\/wp\/v2\/tags?post=26694"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}