Swift Cant通过Lambda将数据发布到DynamoDB

时间:2019-04-04 03:54:43

标签: amazon-web-services amazon-dynamodb

我正在使用AWS Lambda使用无服务器设计来构建iOS应用程序。我已经设置了API网关,并且能够从数据库中获取数据。

虽然我去POST时遇到了问题。我在API网关中,能够成功测试我的API / Lambda关系。我将模型通过Swagger导出并转换为Swift。我的项目中已经导入了这些,并且我试图使用以下函数(saveBtn)来调用post API。似乎一切正常,但是当我查看数据库时,我再也找不到新条目。

下面,我附加了我在XCode中调用的函数以及API Gateway中的模型和集成响应映射。在最底部,我添加了Swagger生成的代码,我认为这一定是问题所在,因为我在APIGateway中进行测试时可以正常工作。

//FUNCTION IN XCODE
...
@IBAction func saveBtn(_ sender: Any) {
        let userData = FullUserData.init(userId: "itsAUserId", birthday: 10041999, city: "Los Angeles", company: "TestCo", education: "high school", identityId: "240", name: "alex lowe", occupation: "software developer", priceRange: 99, salary: 90, userType: 1)

DefaultAPI.saveUserPost(fullUserData: userData) { (resp, error) in
            print(resp)
        }
    }
}

//MODEL FROM API GATEWAY
{
    "title":"fullUserData",
    "type":"object",
    "properties":{
        "userId": {"type":"string"}, 
        "birthday": {"type":"integer"},
        "city": {"type":"string"},
        "company": {"type":"string"}, 
        "education": {"type":"string"},
        "identityId": {"type":"string"},
        "name": {"type":"string"}, 
        "occupation": {"type":"string"},
        "priceRange": {"type":"integer"}, 
        "salary": {"type":"integer"}, 
        "userType": {"type":"integer"}
    }
}


//integration request mapping

#set($inputRoot = $input.path('$'))
{
  "userId" : "$inputRoot.get('userId')",
  "birthday" : "$inputRoot.get('birthday')",
  "city" : "$inputRoot.get('city')",
  "company" : "$inputRoot.get('company')",
  "education" : "$inputRoot.get('education')",
  "identityId" : "$inputRoot.get('identityId')",
  "name" : "$inputRoot.get('name')",
  "occupation" : "$inputRoot.get('occupation')",
  "priceRange" : "$inputRoot.get('priceRange')",
  "salary" : "$inputRoot.get('salary')",
  "userType" : "$inputRoot.get('userType')"
}

    ---
//CODE GENERATED BY SWAGGER

      /getUser:
        get:
      produces:
      - "application/json"
      responses:
        200:
          description: "200 response"
          schema:
            $ref: "#/definitions/Empty"
    post:
      consumes:
      - "application/json"
      produces:
      - "application/json"
      parameters:
      - in: "body"
        name: "fullUserData"
        required: true
        schema:
          $ref: "#/definitions/fullUserData"
      responses:
        200:
          description: "200 response"
          schema:
            $ref: "#/definitions/Empty"
    x-amazon-apigateway-any-method:
      responses:
        200:
          description: "200 response"
      security:
      - sigv4: []
  /getUser/{userId}:
    get:
      consumes:
      - "application/json"
      produces:
      - "application/json"
      parameters:
      - name: "userId"
        in: "path"
        required: true
        type: "string"
      responses:
        200:
          description: "200 response"
          schema:
            $ref: "#/definitions/User"
  /saveUser:
    post:
      consumes:
      - "application/json"
      produces:
      - "application/json"
      parameters:
      - in: "body"
        name: "fullUserData"
        required: true
        schema:
          $ref: "#/definitions/fullUserData"
      responses:
        200:
          description: "200 response"
          schema:
            $ref: "#/definitions/Empty"
    x-amazon-apigateway-any-method:
      responses:
        200:
          description: "200 response"
      security:
      - sigv4: []
securityDefinitions:
  sigv4:
    type: "apiKey"
    name: "Authorization"
    in: "header"
    x-amazon-apigateway-authtype: "awsSigv4"
definitions:
  Empty:
    type: "object"
    title: "Empty Schema"
  User:
    type: "object"
    properties:
      userId:
        type: "string"
    title: "User"
  fullUserData:
    type: "object"
    properties:
      userId:
        type: "string"
      birthday:
        type: "integer"
      city:
        type: "string"
      company:
        type: "string"
      education:
        type: "string"
      identityId:
        type: "string"
      name:
        type: "string"
      occupation:
        type: "string"
      priceRange:
        type: "integer"
      salary:
        type: "integer"
      userType:
        type: "integer"
    title: "fullUserData"
...

0 个答案:

没有答案