用于与S3作为AWS服务的AWS Api Gateway集成的SAM模板 [英] SAM Template for AWS Api Gateway Integration with S3 as AWS Service

查看:90
本文介绍了用于与S3作为AWS服务的AWS Api Gateway集成的SAM模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写SAM模板,我想创建一个API网关,其路径如下:-

I am writing SAM templates and I want to create an API Gateway with the path as follows:-

http:///userFlights/airlines/static/images/{airlineName}.

http:///userFlights/airlines/static/images/{airlineName}.

这应该能够从S3存储桶下载文件.{airlineName}的值可能类似于 IndiGo.jpg .

This should be able to download the file from S3 bucket. The {airlineName} may have value like IndiGo.jpg.

我能够手动创建它.但是,问题是我找不到适合SAM模板的文档.我需要使用SAM自动化我的API网关.

I am able to create this manually. Nevertheless, the problem is I am not able to find the appropriate Documentation for SAM templates. I need to automate my API Gateway with SAM.

值如下:-集成类型-AWS服务

AWS Region- eu-west-3

AWS服务-简单存储服务(S3

Http方法-GET

路径覆盖-航空公司/静态/图片/{airlineName}

推荐答案

您必须使用

You have to make use of an OpenAPI definition using DefinitionBody in your SAM template that defines the API configuration. Check out the S3 proxy example here. I have built an API with the simplest and minimum Swagger definition and deployed via SAM.

AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: AWS SAM template with a S3 integration
Resources:
  ApiGatewayApi:
    Type: AWS::Serverless::Api
    Properties:
      StageName: prod
      DefinitionBody: {
        "swagger": "2.0",
        "info": {
          "version": "1.0"
        },
        "paths": {
          "/airlines/static/images/{airlineName}": {
            "get": {
              "produces": [
                "application/json"
              ],
              "responses": {
                "200": {
                  "description": "200 response"
                }
              },
              "x-amazon-apigateway-integration": {
                "responses": {
                  "default": {
                    "statusCode": "200"
                  }
                },
                "credentials": "arn:aws:iam::{account-id}:role/{role-name}",
                "uri": "arn:aws:apigateway:{aws-region}:s3:path/{bucket-name}",
                "passthroughBehavior": "when_no_match",
                "httpMethod": "GET",
                "type": "aws"
              }
            }
          }
        }
      }

这篇关于用于与S3作为AWS服务的AWS Api Gateway集成的SAM模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆