Using Mapping into Cloudformation, and openapi Yaml
Par Arnaud Charlier, vendredi 11 janvier 2019 à 13:32 :: AWS :: #59 :: rss
How to declare a mapping in your cloudformation and use it in your Linked openapi.yml file
Problem : declare a mapping and use it in your openapi.yml file
The cloudformation :
AWSTemplateFormatVersion: '2010-09-09'
Transform: 'AWS::Serverless-2016-10-31'
Parameters:
Env:
Type: String
Default: dev
AllowedValues:
- sandbox
- dev
- test
- prod
Mappings:
CDN:
prod:
value: https://media.arnaudcharlier.be
test:
value: https://media-test.arnaudcharlier.be
dev:
value: https://1afezfe124djezs.cloudfront.net
sandbox:
value: https://d1rz2vdzdzdzafezs.cloudfront.net
Resources:
###############
# API Gateway #
###############
ApiGateway:
Type: AWS::Serverless::Api
Properties:
Name: !Sub media-api
StageName: !Sub ${Env}
EndpointConfiguration: REGIONAL
DefinitionBody:
Fn::Transform:
Name: 'AWS::Include'
Parameters:
Location: ./openapi.yml
openapi.yml
openapi: 3.0.0
servers: []
info:
version: "2.0"
title: Media MicroService endpoint documentation
x-definitions:
enums:
Status:
enum: &Status [INITIATED, SAVED, PUBLISHED, UNPUBLISHED]
GrabStatus:
enum: &GrabStatus [STARTED, IN_PROCESS, ERROR, VALID, SKIP]
paths:
/{objectType}/{objectId}/{fileType}:
get:
tags:
- Cars
summary: Retrieve all media of a type for a given objectId
security:
- api_key: []
parameters:
- name: objectType
in: path
description: Object type
required: true
schema:
type: string
- name: objectId
in: path
description: ID of the object
required: true
schema:
type: integer
- name: fileType
in: path
required: true
description: File type (pictures, pdfs or videos)
schema:
type: string
- name: source
in: query
required: false
description: full or raw (default to full)
schema:
type: string
- name: path
in: query
required: false
description: absolute or relative (default to absolute)
schema:
type: string
responses:
'200':
description: OK
content:
application/vnd.be.media.pictures.v2+json:
schema:
type: array
items:
$ref: '#/components/schemas/Picture'
x-amazon-apigateway-integration:
httpMethod: POST
type: aws_proxy
uri:
Fn::Sub: "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${GetMedia.Arn}/invocations"
post:
tags:
- Classifieds
summary: Create new media for a given Object ID
security:
- api_key: []
parameters:
- name: key
in: query
description: Bucket key (ex classifieds/14567/image.png)
required: true
schema:
type: string
- name: Content-Type
in: header
description: Content type
required: true
schema:
type: string
- name: Content-Length
in: header
description: Content length
required: true
schema:
type: string
requestBody:
description: File to be uploaded
required: true
content:
image/png:
schema:
type: string
format: binary
image/jpeg:
schema:
type: string
format: binary
video/x-msvideo:
schema:
type: string
format: binary
application/pdf:
schema:
type: string
format: binary
responses:
'204':
description: OK
headers:
Content-Type:
schema:
type: string
Content-Length:
schema:
type: string
ETag:
schema:
type: string
X-CDN:
schema:
type: string
'400':
description: Error - Bad request
headers:
Content-Type:
schema:
type: string
Content-Length:
schema:
type: string
'415':
description: Error - Unsupported media type
headers:
Content-Type:
schema:
type: string
Content-Length:
schema:
type: string
'500':
description: Error - Internal error
headers:
Content-Type:
schema:
type: string
Content-Length:
schema:
type: string
x-amazon-apigateway-integration:
credentials:
Fn::GetAtt:
- ApiGatewayWriteS3Role
- Arn
uri:
Fn::Sub: arn:aws:apigateway:${AWS::Region}:s3:path/{bucket}/{key}
passthroughBehavior: when_no_match
httpMethod: PUT
type: aws
requestParameters:
integration.request.header.Content-Length: method.request.header.Content-Length
integration.request.header.Content-Type: method.request.header.Content-Type
integration.request.path.bucket:
Fn::Sub:
- "'${Bucket}'"
- Bucket:
Fn::FindInMap:
- 'MediaBucketName'
- Ref: 'Env'
- 'value'
integration.request.path.key: method.request.querystring.key
responses:
default:
statusCode: 204
responseParameters:
method.response.header.Content-Type: integration.response.header.Content-Type
method.response.header.Content-Length: integration.response.header.Content-Length
method.response.header.ETag: integration.response.header.ETag
method.response.header.X-CDN:
Fn::Sub:
- "'${CDN}'"
- CDN:
Fn::FindInMap:
- 'CDN'
- Ref: 'Env'
- 'value'
'4\\d{2}':
statusCode: 400
'5\\d{2}':
statusCode: 500
Commentaires
1. Le jeudi 31 janvier 2019 à 23:58, par Arnaud Charlier
Ajouter un commentaire
Les commentaires pour ce billet sont fermés.