Created
October 5, 2022 12:25
-
-
Save allenheltondev/4337bfc2165c4ef0bc31517159fede90 to your computer and use it in GitHub Desktop.
Integrating API Gateway to Amazon Translate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
openapi: 3.0.0 | |
info: | |
title: AWS Service Integration API | |
version: 1.0.0 | |
paths: | |
/translations: | |
post: | |
requestBody: | |
required: true | |
content: | |
application/json: | |
schema: | |
$ref: '#/components/schemas/translateText' | |
responses: | |
200: | |
$ref: '#/components/responses/ok' | |
x-amazon-apigateway-request-validator: Validate All | |
x-amazon-apigateway-integration: | |
credentials: | |
Fn::Sub: ${TranslateTextRole.Arn} | |
uri: | |
Fn::Sub: arn:${AWS::Partition}:apigateway:${AWS::Region}:translate:path/${AWS::AccountId} | |
httpMethod: POST | |
type: aws | |
passthroughBehavior: never | |
requestParameters: | |
integration.request.header.Content-Type: "'application/x-amz-json-1.1'" | |
integration.request.header.X-Amz-Target: "'AWSShineFrontendService_20170701.TranslateText'" | |
requestTemplates: | |
application/json: | | |
{ | |
"SourceLanguageCode": "en", | |
"TargetLanguageCode": "es", | |
"Text": "$input.path('$.text')" | |
} | |
responses: | |
200: | |
statusCode: 200 | |
responseTemplates: | |
application/json: | | |
{ | |
"translatedText": "$input.path('$.TranslatedText')" | |
} | |
components: | |
schemas: | |
translateText: | |
type: object | |
required: | |
- text | |
properties: | |
text: | |
type: string | |
responses: | |
ok: | |
content: | |
application/json: | |
schema: | |
type: object | |
required: | |
- translatedText | |
properties: | |
translatedText: | |
type: string |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AWSTemplateFormatVersion: '2010-09-09' | |
Transform: AWS::Serverless-2016-10-31 | |
Description: > | |
Example template to show how to integrate an AWS service to API Gateway | |
Resources: | |
Api: | |
Type: AWS::Serverless::Api | |
Properties: | |
TracingEnabled: false | |
StageName: dev | |
DefinitionBody: | |
Fn::Transform: | |
Name: AWS::Include | |
Parameters: | |
Location: ./openapi.yaml | |
TranslateTextRole: | |
Type: AWS::IAM::Role | |
Properties: | |
AssumeRolePolicyDocument: | |
Version: 2012-10-17 | |
Statement: | |
- Effect: Allow | |
Principal: | |
Service: | |
- apigateway.amazonaws.com | |
Action: | |
- sts:AssumeRole | |
Policies: | |
- PolicyName: TranslateTextPolicy | |
PolicyDocument: | |
Version: 2012-10-17 | |
Statement: | |
- Effect: Allow | |
Action: | |
- translate:TranslateText | |
Resource: '*' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment