AWS SAM usage

Behind the scenes, AWS SAM uses AWS CloudFormation's change sets functionality (http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-updating-stacks-changesets.html). In order to create our serverless weather microservice example using SAM, follow these steps:

  1. Download the SAM YAML template, API Gateway Swagger file, and AWS Lambda code .zip file in a single directory.
  2. Create an Amazon S3 bucket (from the AWS console or the API) with any available name, such as CloudNative-WeatherService.
  3. Now, it's time to upload the Lambda code and Swagger API file definition to the S3 bucket you created in the previous step and then update the SAM YAML file with their S3 locations. To do this, you can use the following AWS CLI command, which automatically handles all of this and creates a resultant SAM YAML file, which can be used in successive steps:
aws Cloudformation package 
--template-file ./Cloudnative-weather-microservice.yaml
--s3-bucket CloudNative-WeatherService --output-template-file Cloudnative-weather-microservice-packaged.yaml
If you don't have AWS CLI already installed and configured, then please refer the AWS documentation at http://docs.aws.amazon.com/cli/latest/userguide/installing.html.
  1. Once the packaging command is completed successfully, the next step is to start with the actual deployment. For this, use the following command, specifying the packaged YAML file from the previous step and the name of the stack that you are about to create:
aws Cloudformation deploy      
--template-file ./Cloudnative-weather-microservice=-packaged.yaml
--stack-name weather-service-stack      
--capabilities CAPABILITY_IAM     
  1. Once the preceding command completes successfully, you can go to the AWS CloudFormation console to see the stack status there. From the Outputs tab of the completed CloudFormation stack, you will see a parameter called ApiURL with a value of your API Gateway's Weather Service API endpoint. With that, your API is all set and you can test the same using the procedure which was explained in previous sections.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset