Creating the API with a CloudFormation template

Now, let's create the API by using a CloudFormation template. We will not discuss the components that were already discussed in previous recipes, nor will we discuss the theory for commands that were already discussed within the CLI commands section. The complete code is available in the code files.

With the CloudFormation template, the major change is within the Integration property of the resource type AWS::ApiGateway::Method, as follows:

Integration:
Type: AWS
IntegrationHttpMethod: POST
PassthroughBehavior: WHEN_NO_TEMPLATES
RequestTemplates:
application/json: "{ "name" : $input.json('$.user.name'), "time": $input.json('$.greeting.time') }"
IntegrationResponses:
- StatusCode: 200
ResponseTemplates:
application/json: "{ "greeting" : $input.json('$.message')}"
Uri:
!Sub
- 'arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/arn:aws:lambda:us-east-1:${AWS::AccountId}:function:${LAMBDA_NAME}/invocations'
- LAMBDA_NAME: !ImportValue LambdaForApiGateway
All of the other components (for example, template version, description, API, resource, deployment, adding permission, and output) remain the same, except for the descriptions and names (in a few places), which are changed to match the current recipe.
..................Content has been hidden....................

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