iOS SDK generated by AWS API Gateway is missing required 'defaultClient' memberIs there a way to change the http status codes returned by Amazon API Gateway?How to pass a querystring or route parameter to AWS Lambda from Amazon API GatewayAccess HTTP request (headers, query string, cookies, body) object in lambda with http endpointAWS API gateway with STS and Custom Authenticator — anyone with example with browser client?Code signing is required for product type 'Application' in SDK 'iOS 10.0' - StickerPackExtension requires a development team errorUsing an api key in amazon api gatewayMissing Authentication Token while accessing API Gateway?AWS lambda api gateway error “Malformed Lambda proxy response”Missing required client configuration options: regionAWS Api Gateway: Missing Authentication Token

Was the Lonely Mountain, where Smaug lived, a volcano?

Which are the methodologies for interpreting Vedas?

What class is best to play when a level behind the rest of the party?

Does WiFi affect the quality of images downloaded from the internet?

Table with varying step

Is it good practice to create tables dynamically?

As easy as Three, Two, One... How fast can you go from Five to Four?

Am I allowed to determine tenets of my contract as a warlock?

How do I type a hyphen in iOS 12?

What are some of the expected properties of metallic glasses and some steps to create them? (semi-ELI5)

Purpose of cylindrical attachments on Power Transmission towers

In Pandemic, why take the extra step of eradicating a disease after you've cured it?

ISP is not hashing the password I log in with online. Should I take any action?

Generate parentheses solution

New Site Design!

Can you open the door or die? v2

Can I use 220 V outlets on a 15 ampere breaker and wire it up as 110 V?

I sent an angry e-mail to my interviewers about a conflict at my home institution. Could this affect my application?

usage of mir gefallen

Why didn't all the iron and heavier elements find their way to the center of the accretion disc in the early solar system?

Is it a good security practice to force employees hide their employer to avoid being targeted?

Dedicated bike GPS computer over smartphone

David slept with Bathsheba because she was pure?? What does that mean?

How to remove the empty page that is placed after the ToC, List of figures and List of tables



iOS SDK generated by AWS API Gateway is missing required 'defaultClient' member


Is there a way to change the http status codes returned by Amazon API Gateway?How to pass a querystring or route parameter to AWS Lambda from Amazon API GatewayAccess HTTP request (headers, query string, cookies, body) object in lambda with http endpointAWS API gateway with STS and Custom Authenticator — anyone with example with browser client?Code signing is required for product type 'Application' in SDK 'iOS 10.0' - StickerPackExtension requires a development team errorUsing an api key in amazon api gatewayMissing Authentication Token while accessing API Gateway?AWS lambda api gateway error “Malformed Lambda proxy response”Missing required client configuration options: regionAWS Api Gateway: Missing Authentication Token






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I've followed two API Gateway tutorials for two different REST APIs that call AWS Lambda. Here's the link to the Calc API, which is the subject of this post.



In each case, test invocations via the AWS Console work perfectly. But when I generate the iOS Swift SDK from the deployed stage 'SDK Generation' tab, unzip and import into my Xcode project, the defaultClient member is missing in <API-Name>Client.swift.



The README.md file in each case says it should be there:



# Use the SDK in your project

1. Grab the `defaultClient` from your code

let client = <API-Name>Client.defaultClient()

1. You can now call your method using the client SDK


But there is NO defaultClient in <API-Name>Client.swift.



UPDATE
There is no defaultClient, but there is a default (with backticks around it because default is a reserved word in Swift). So I substituted that in the REST API invocation... and it worked! I have no idea why... I don't know what the backticks mean in Swift... and if someone can explain this to me, great. But I verified via API Gateway that the API was called successfully; and I verified via Cloudwatch that the Lambda function returns the correct value.



Here is my code that invokes the API:



@IBAction func userInvokeApi(_ sender: UIButton) 
print("You clicked invoke api...")
let client = SVTLambdaGateClient.default()
client.calcGet(operand2: "3", _operator: "+", operand1: "5").continueWith (task: AWSTask?) -> AnyObject? in
if let error = task?.error
print("Error occurred: (error)")
return nil


if let result = task?.result
// Do something with result
print("The result is... (result)")


return nil




However, I don't understand the data structure returned at the Client yet. This is what I get:



You clicked invoke api...
The result is... <AmplifyRestApiTest.Empty: 0x600002020770>



Here are the full contents of the generated <API-Name>Client.swift file (with some comments removed). I'm thinking it's possible that the README is no longer in sync with the SDK generation.



import AWSCore
import AWSAPIGateway

public class SVTLambdaGateClient: AWSAPIGatewayClient {

static let AWSInfoClientKey = "SVTLambdaGateClient"

private static let _serviceClients = AWSSynchronizedMutableDictionary()
private static let _defaultClient:SVTLambdaGateClient =
var serviceConfiguration: AWSServiceConfiguration? = nil
let serviceInfo = AWSInfo.default().defaultServiceInfo(AWSInfoClientKey)
if let serviceInfo = serviceInfo
serviceConfiguration = AWSServiceConfiguration(region: serviceInfo.region, credentialsProvider: serviceInfo.cognitoCredentialsProvider)
else if (AWSServiceManager.default().defaultServiceConfiguration != nil)
serviceConfiguration = AWSServiceManager.default().defaultServiceConfiguration
else
serviceConfiguration = AWSServiceConfiguration(region: .Unknown, credentialsProvider: nil)


return SVTLambdaGateClient(configuration: serviceConfiguration!)
()

/**
Returns the singleton service client. If the singleton object does not exist, the SDK instantiates the default service client with `defaultServiceConfiguration` from `AWSServiceManager.defaultServiceManager()`. The reference to this object is maintained by the SDK, and you do not need to retain it manually.
@return The default service client.
*/

public class func `default`() -> SVTLambdaGateClient
return _defaultClient


/**
Creates a service client with the given service configuration and registers it for the key.
@param configuration A service configuration object.
@param key A string to identify the service client.
*/

public class func registerClient(withConfiguration configuration: AWSServiceConfiguration, forKey key: String)
_serviceClients.setObject(SVTLambdaGateClient(configuration: configuration), forKey: key as NSString);


/**
Retrieves the service client associated with the key. You need to call `registerClient(withConfiguration:configuration, forKey:)` before invoking this method or alternatively, set the configuration in your application's `info.plist` file. If `registerClientWithConfiguration(configuration, forKey:)` has not been called in advance or if a configuration is not present in the `info.plist` file of the app, this method returns `nil`.
Then call the following to get the service client:

let serviceClient = SVTLambdaGateClient.client(forKey: "USWest2SVTLambdaGateClient")

@param key A string to identify the service client.
@return An instance of the service client.
*/
public class func client(forKey key: String) -> SVTLambdaGateClient
objc_sync_enter(self)
if let client: SVTLambdaGateClient = _serviceClients.object(forKey: key) as? SVTLambdaGateClient
objc_sync_exit(self)
return client


let serviceInfo = AWSInfo.default().defaultServiceInfo(AWSInfoClientKey)
if let serviceInfo = serviceInfo
let serviceConfiguration = AWSServiceConfiguration(region: serviceInfo.region, credentialsProvider: serviceInfo.cognitoCredentialsProvider)
SVTLambdaGateClient.registerClient(withConfiguration: serviceConfiguration!, forKey: key)

objc_sync_exit(self)
return _serviceClients.object(forKey: key) as! SVTLambdaGateClient;


/**
Removes the service client associated with the key and release it.

@param key A string to identify the service client.
*/
public class func removeClient(forKey key: String) -> Void
_serviceClients.remove(key)


init(configuration: AWSServiceConfiguration)
super.init()

self.configuration = configuration.copy() as! AWSServiceConfiguration
var URLString: String = "https://<my-api-id>.execute-api.us-east-2.amazonaws.com/test"
if URLString.hasSuffix("/")
URLString = URLString.substring(to: URLString.index(before: URLString.endIndex))

self.configuration.endpoint = AWSEndpoint(region: configuration.regionType, service: .APIGateway, url: URL(string: URLString))
let signer: AWSSignatureV4Signer = AWSSignatureV4Signer(credentialsProvider: configuration.credentialsProvider, endpoint: self.configuration.endpoint)
if let endpoint = self.configuration.endpoint
self.configuration.baseURL = endpoint.url

self.configuration.requestInterceptors = [AWSNetworkingRequestInterceptor(), signer]


/*


@param operand2
@param _operator
@param operand1

return type: Empty
*/
public func calcGet(operand2: String, _operator: String, operand1: String) -> AWSTask<Empty>
let headerParameters = [
"Content-Type": "application/json",
"Accept": "application/json",

]

var queryParameters:[String:Any] = [:]
queryParameters["operand2"] = operand2
queryParameters["operator"] = _operator
queryParameters["operand1"] = operand1

let pathParameters:[String:Any] = [:]

return self.invokeHTTPRequest("GET", urlString: "/calc", pathParameters: pathParameters, queryParameters: queryParameters, headerParameters: headerParameters, body: nil, responseClass: Empty.self) as! AWSTask<Empty>



/*


@param body

return type: Empty
*/
public func calcPost(body: SVTInput) -> AWSTask<Empty>
let headerParameters = [
"Content-Type": "application/json",
"Accept": "application/json",

]

let queryParameters:[String:Any] = [:]

let pathParameters:[String:Any] = [:]

return self.invokeHTTPRequest("POST", urlString: "/calc", pathParameters: pathParameters, queryParameters: queryParameters, headerParameters: headerParameters, body: body, responseClass: Empty.self) as! AWSTask<Empty>



/*


@param operand2
@param _operator
@param operand1

return type: SVTResult
*/
public func calcOperand1Operand2OperatorGet(operand2: String, _operator: String, operand1: String) -> AWSTask<SVTResult>
let headerParameters = [
"Content-Type": "application/json",
"Accept": "application/json",

]

let queryParameters:[String:Any] = [:]

var pathParameters:[String:Any] = [:]
pathParameters["operand2"] = operand2
pathParameters["operator"] = _operator
pathParameters["operand1"] = operand1

return self.invokeHTTPRequest("GET", urlString: "/calc/operand1/operand2/operator", pathParameters: pathParameters, queryParameters: queryParameters, headerParameters: headerParameters, body: nil, responseClass: SVTResult.self) as! AWSTask<SVTResult>



Any help greatly appreciated!










share|improve this question






























    0















    I've followed two API Gateway tutorials for two different REST APIs that call AWS Lambda. Here's the link to the Calc API, which is the subject of this post.



    In each case, test invocations via the AWS Console work perfectly. But when I generate the iOS Swift SDK from the deployed stage 'SDK Generation' tab, unzip and import into my Xcode project, the defaultClient member is missing in <API-Name>Client.swift.



    The README.md file in each case says it should be there:



    # Use the SDK in your project

    1. Grab the `defaultClient` from your code

    let client = <API-Name>Client.defaultClient()

    1. You can now call your method using the client SDK


    But there is NO defaultClient in <API-Name>Client.swift.



    UPDATE
    There is no defaultClient, but there is a default (with backticks around it because default is a reserved word in Swift). So I substituted that in the REST API invocation... and it worked! I have no idea why... I don't know what the backticks mean in Swift... and if someone can explain this to me, great. But I verified via API Gateway that the API was called successfully; and I verified via Cloudwatch that the Lambda function returns the correct value.



    Here is my code that invokes the API:



    @IBAction func userInvokeApi(_ sender: UIButton) 
    print("You clicked invoke api...")
    let client = SVTLambdaGateClient.default()
    client.calcGet(operand2: "3", _operator: "+", operand1: "5").continueWith (task: AWSTask?) -> AnyObject? in
    if let error = task?.error
    print("Error occurred: (error)")
    return nil


    if let result = task?.result
    // Do something with result
    print("The result is... (result)")


    return nil




    However, I don't understand the data structure returned at the Client yet. This is what I get:



    You clicked invoke api...
    The result is... <AmplifyRestApiTest.Empty: 0x600002020770>



    Here are the full contents of the generated <API-Name>Client.swift file (with some comments removed). I'm thinking it's possible that the README is no longer in sync with the SDK generation.



    import AWSCore
    import AWSAPIGateway

    public class SVTLambdaGateClient: AWSAPIGatewayClient {

    static let AWSInfoClientKey = "SVTLambdaGateClient"

    private static let _serviceClients = AWSSynchronizedMutableDictionary()
    private static let _defaultClient:SVTLambdaGateClient =
    var serviceConfiguration: AWSServiceConfiguration? = nil
    let serviceInfo = AWSInfo.default().defaultServiceInfo(AWSInfoClientKey)
    if let serviceInfo = serviceInfo
    serviceConfiguration = AWSServiceConfiguration(region: serviceInfo.region, credentialsProvider: serviceInfo.cognitoCredentialsProvider)
    else if (AWSServiceManager.default().defaultServiceConfiguration != nil)
    serviceConfiguration = AWSServiceManager.default().defaultServiceConfiguration
    else
    serviceConfiguration = AWSServiceConfiguration(region: .Unknown, credentialsProvider: nil)


    return SVTLambdaGateClient(configuration: serviceConfiguration!)
    ()

    /**
    Returns the singleton service client. If the singleton object does not exist, the SDK instantiates the default service client with `defaultServiceConfiguration` from `AWSServiceManager.defaultServiceManager()`. The reference to this object is maintained by the SDK, and you do not need to retain it manually.
    @return The default service client.
    */

    public class func `default`() -> SVTLambdaGateClient
    return _defaultClient


    /**
    Creates a service client with the given service configuration and registers it for the key.
    @param configuration A service configuration object.
    @param key A string to identify the service client.
    */

    public class func registerClient(withConfiguration configuration: AWSServiceConfiguration, forKey key: String)
    _serviceClients.setObject(SVTLambdaGateClient(configuration: configuration), forKey: key as NSString);


    /**
    Retrieves the service client associated with the key. You need to call `registerClient(withConfiguration:configuration, forKey:)` before invoking this method or alternatively, set the configuration in your application's `info.plist` file. If `registerClientWithConfiguration(configuration, forKey:)` has not been called in advance or if a configuration is not present in the `info.plist` file of the app, this method returns `nil`.
    Then call the following to get the service client:

    let serviceClient = SVTLambdaGateClient.client(forKey: "USWest2SVTLambdaGateClient")

    @param key A string to identify the service client.
    @return An instance of the service client.
    */
    public class func client(forKey key: String) -> SVTLambdaGateClient
    objc_sync_enter(self)
    if let client: SVTLambdaGateClient = _serviceClients.object(forKey: key) as? SVTLambdaGateClient
    objc_sync_exit(self)
    return client


    let serviceInfo = AWSInfo.default().defaultServiceInfo(AWSInfoClientKey)
    if let serviceInfo = serviceInfo
    let serviceConfiguration = AWSServiceConfiguration(region: serviceInfo.region, credentialsProvider: serviceInfo.cognitoCredentialsProvider)
    SVTLambdaGateClient.registerClient(withConfiguration: serviceConfiguration!, forKey: key)

    objc_sync_exit(self)
    return _serviceClients.object(forKey: key) as! SVTLambdaGateClient;


    /**
    Removes the service client associated with the key and release it.

    @param key A string to identify the service client.
    */
    public class func removeClient(forKey key: String) -> Void
    _serviceClients.remove(key)


    init(configuration: AWSServiceConfiguration)
    super.init()

    self.configuration = configuration.copy() as! AWSServiceConfiguration
    var URLString: String = "https://<my-api-id>.execute-api.us-east-2.amazonaws.com/test"
    if URLString.hasSuffix("/")
    URLString = URLString.substring(to: URLString.index(before: URLString.endIndex))

    self.configuration.endpoint = AWSEndpoint(region: configuration.regionType, service: .APIGateway, url: URL(string: URLString))
    let signer: AWSSignatureV4Signer = AWSSignatureV4Signer(credentialsProvider: configuration.credentialsProvider, endpoint: self.configuration.endpoint)
    if let endpoint = self.configuration.endpoint
    self.configuration.baseURL = endpoint.url

    self.configuration.requestInterceptors = [AWSNetworkingRequestInterceptor(), signer]


    /*


    @param operand2
    @param _operator
    @param operand1

    return type: Empty
    */
    public func calcGet(operand2: String, _operator: String, operand1: String) -> AWSTask<Empty>
    let headerParameters = [
    "Content-Type": "application/json",
    "Accept": "application/json",

    ]

    var queryParameters:[String:Any] = [:]
    queryParameters["operand2"] = operand2
    queryParameters["operator"] = _operator
    queryParameters["operand1"] = operand1

    let pathParameters:[String:Any] = [:]

    return self.invokeHTTPRequest("GET", urlString: "/calc", pathParameters: pathParameters, queryParameters: queryParameters, headerParameters: headerParameters, body: nil, responseClass: Empty.self) as! AWSTask<Empty>



    /*


    @param body

    return type: Empty
    */
    public func calcPost(body: SVTInput) -> AWSTask<Empty>
    let headerParameters = [
    "Content-Type": "application/json",
    "Accept": "application/json",

    ]

    let queryParameters:[String:Any] = [:]

    let pathParameters:[String:Any] = [:]

    return self.invokeHTTPRequest("POST", urlString: "/calc", pathParameters: pathParameters, queryParameters: queryParameters, headerParameters: headerParameters, body: body, responseClass: Empty.self) as! AWSTask<Empty>



    /*


    @param operand2
    @param _operator
    @param operand1

    return type: SVTResult
    */
    public func calcOperand1Operand2OperatorGet(operand2: String, _operator: String, operand1: String) -> AWSTask<SVTResult>
    let headerParameters = [
    "Content-Type": "application/json",
    "Accept": "application/json",

    ]

    let queryParameters:[String:Any] = [:]

    var pathParameters:[String:Any] = [:]
    pathParameters["operand2"] = operand2
    pathParameters["operator"] = _operator
    pathParameters["operand1"] = operand1

    return self.invokeHTTPRequest("GET", urlString: "/calc/operand1/operand2/operator", pathParameters: pathParameters, queryParameters: queryParameters, headerParameters: headerParameters, body: nil, responseClass: SVTResult.self) as! AWSTask<SVTResult>



    Any help greatly appreciated!










    share|improve this question


























      0












      0








      0








      I've followed two API Gateway tutorials for two different REST APIs that call AWS Lambda. Here's the link to the Calc API, which is the subject of this post.



      In each case, test invocations via the AWS Console work perfectly. But when I generate the iOS Swift SDK from the deployed stage 'SDK Generation' tab, unzip and import into my Xcode project, the defaultClient member is missing in <API-Name>Client.swift.



      The README.md file in each case says it should be there:



      # Use the SDK in your project

      1. Grab the `defaultClient` from your code

      let client = <API-Name>Client.defaultClient()

      1. You can now call your method using the client SDK


      But there is NO defaultClient in <API-Name>Client.swift.



      UPDATE
      There is no defaultClient, but there is a default (with backticks around it because default is a reserved word in Swift). So I substituted that in the REST API invocation... and it worked! I have no idea why... I don't know what the backticks mean in Swift... and if someone can explain this to me, great. But I verified via API Gateway that the API was called successfully; and I verified via Cloudwatch that the Lambda function returns the correct value.



      Here is my code that invokes the API:



      @IBAction func userInvokeApi(_ sender: UIButton) 
      print("You clicked invoke api...")
      let client = SVTLambdaGateClient.default()
      client.calcGet(operand2: "3", _operator: "+", operand1: "5").continueWith (task: AWSTask?) -> AnyObject? in
      if let error = task?.error
      print("Error occurred: (error)")
      return nil


      if let result = task?.result
      // Do something with result
      print("The result is... (result)")


      return nil




      However, I don't understand the data structure returned at the Client yet. This is what I get:



      You clicked invoke api...
      The result is... <AmplifyRestApiTest.Empty: 0x600002020770>



      Here are the full contents of the generated <API-Name>Client.swift file (with some comments removed). I'm thinking it's possible that the README is no longer in sync with the SDK generation.



      import AWSCore
      import AWSAPIGateway

      public class SVTLambdaGateClient: AWSAPIGatewayClient {

      static let AWSInfoClientKey = "SVTLambdaGateClient"

      private static let _serviceClients = AWSSynchronizedMutableDictionary()
      private static let _defaultClient:SVTLambdaGateClient =
      var serviceConfiguration: AWSServiceConfiguration? = nil
      let serviceInfo = AWSInfo.default().defaultServiceInfo(AWSInfoClientKey)
      if let serviceInfo = serviceInfo
      serviceConfiguration = AWSServiceConfiguration(region: serviceInfo.region, credentialsProvider: serviceInfo.cognitoCredentialsProvider)
      else if (AWSServiceManager.default().defaultServiceConfiguration != nil)
      serviceConfiguration = AWSServiceManager.default().defaultServiceConfiguration
      else
      serviceConfiguration = AWSServiceConfiguration(region: .Unknown, credentialsProvider: nil)


      return SVTLambdaGateClient(configuration: serviceConfiguration!)
      ()

      /**
      Returns the singleton service client. If the singleton object does not exist, the SDK instantiates the default service client with `defaultServiceConfiguration` from `AWSServiceManager.defaultServiceManager()`. The reference to this object is maintained by the SDK, and you do not need to retain it manually.
      @return The default service client.
      */

      public class func `default`() -> SVTLambdaGateClient
      return _defaultClient


      /**
      Creates a service client with the given service configuration and registers it for the key.
      @param configuration A service configuration object.
      @param key A string to identify the service client.
      */

      public class func registerClient(withConfiguration configuration: AWSServiceConfiguration, forKey key: String)
      _serviceClients.setObject(SVTLambdaGateClient(configuration: configuration), forKey: key as NSString);


      /**
      Retrieves the service client associated with the key. You need to call `registerClient(withConfiguration:configuration, forKey:)` before invoking this method or alternatively, set the configuration in your application's `info.plist` file. If `registerClientWithConfiguration(configuration, forKey:)` has not been called in advance or if a configuration is not present in the `info.plist` file of the app, this method returns `nil`.
      Then call the following to get the service client:

      let serviceClient = SVTLambdaGateClient.client(forKey: "USWest2SVTLambdaGateClient")

      @param key A string to identify the service client.
      @return An instance of the service client.
      */
      public class func client(forKey key: String) -> SVTLambdaGateClient
      objc_sync_enter(self)
      if let client: SVTLambdaGateClient = _serviceClients.object(forKey: key) as? SVTLambdaGateClient
      objc_sync_exit(self)
      return client


      let serviceInfo = AWSInfo.default().defaultServiceInfo(AWSInfoClientKey)
      if let serviceInfo = serviceInfo
      let serviceConfiguration = AWSServiceConfiguration(region: serviceInfo.region, credentialsProvider: serviceInfo.cognitoCredentialsProvider)
      SVTLambdaGateClient.registerClient(withConfiguration: serviceConfiguration!, forKey: key)

      objc_sync_exit(self)
      return _serviceClients.object(forKey: key) as! SVTLambdaGateClient;


      /**
      Removes the service client associated with the key and release it.

      @param key A string to identify the service client.
      */
      public class func removeClient(forKey key: String) -> Void
      _serviceClients.remove(key)


      init(configuration: AWSServiceConfiguration)
      super.init()

      self.configuration = configuration.copy() as! AWSServiceConfiguration
      var URLString: String = "https://<my-api-id>.execute-api.us-east-2.amazonaws.com/test"
      if URLString.hasSuffix("/")
      URLString = URLString.substring(to: URLString.index(before: URLString.endIndex))

      self.configuration.endpoint = AWSEndpoint(region: configuration.regionType, service: .APIGateway, url: URL(string: URLString))
      let signer: AWSSignatureV4Signer = AWSSignatureV4Signer(credentialsProvider: configuration.credentialsProvider, endpoint: self.configuration.endpoint)
      if let endpoint = self.configuration.endpoint
      self.configuration.baseURL = endpoint.url

      self.configuration.requestInterceptors = [AWSNetworkingRequestInterceptor(), signer]


      /*


      @param operand2
      @param _operator
      @param operand1

      return type: Empty
      */
      public func calcGet(operand2: String, _operator: String, operand1: String) -> AWSTask<Empty>
      let headerParameters = [
      "Content-Type": "application/json",
      "Accept": "application/json",

      ]

      var queryParameters:[String:Any] = [:]
      queryParameters["operand2"] = operand2
      queryParameters["operator"] = _operator
      queryParameters["operand1"] = operand1

      let pathParameters:[String:Any] = [:]

      return self.invokeHTTPRequest("GET", urlString: "/calc", pathParameters: pathParameters, queryParameters: queryParameters, headerParameters: headerParameters, body: nil, responseClass: Empty.self) as! AWSTask<Empty>



      /*


      @param body

      return type: Empty
      */
      public func calcPost(body: SVTInput) -> AWSTask<Empty>
      let headerParameters = [
      "Content-Type": "application/json",
      "Accept": "application/json",

      ]

      let queryParameters:[String:Any] = [:]

      let pathParameters:[String:Any] = [:]

      return self.invokeHTTPRequest("POST", urlString: "/calc", pathParameters: pathParameters, queryParameters: queryParameters, headerParameters: headerParameters, body: body, responseClass: Empty.self) as! AWSTask<Empty>



      /*


      @param operand2
      @param _operator
      @param operand1

      return type: SVTResult
      */
      public func calcOperand1Operand2OperatorGet(operand2: String, _operator: String, operand1: String) -> AWSTask<SVTResult>
      let headerParameters = [
      "Content-Type": "application/json",
      "Accept": "application/json",

      ]

      let queryParameters:[String:Any] = [:]

      var pathParameters:[String:Any] = [:]
      pathParameters["operand2"] = operand2
      pathParameters["operator"] = _operator
      pathParameters["operand1"] = operand1

      return self.invokeHTTPRequest("GET", urlString: "/calc/operand1/operand2/operator", pathParameters: pathParameters, queryParameters: queryParameters, headerParameters: headerParameters, body: nil, responseClass: SVTResult.self) as! AWSTask<SVTResult>



      Any help greatly appreciated!










      share|improve this question
















      I've followed two API Gateway tutorials for two different REST APIs that call AWS Lambda. Here's the link to the Calc API, which is the subject of this post.



      In each case, test invocations via the AWS Console work perfectly. But when I generate the iOS Swift SDK from the deployed stage 'SDK Generation' tab, unzip and import into my Xcode project, the defaultClient member is missing in <API-Name>Client.swift.



      The README.md file in each case says it should be there:



      # Use the SDK in your project

      1. Grab the `defaultClient` from your code

      let client = <API-Name>Client.defaultClient()

      1. You can now call your method using the client SDK


      But there is NO defaultClient in <API-Name>Client.swift.



      UPDATE
      There is no defaultClient, but there is a default (with backticks around it because default is a reserved word in Swift). So I substituted that in the REST API invocation... and it worked! I have no idea why... I don't know what the backticks mean in Swift... and if someone can explain this to me, great. But I verified via API Gateway that the API was called successfully; and I verified via Cloudwatch that the Lambda function returns the correct value.



      Here is my code that invokes the API:



      @IBAction func userInvokeApi(_ sender: UIButton) 
      print("You clicked invoke api...")
      let client = SVTLambdaGateClient.default()
      client.calcGet(operand2: "3", _operator: "+", operand1: "5").continueWith (task: AWSTask?) -> AnyObject? in
      if let error = task?.error
      print("Error occurred: (error)")
      return nil


      if let result = task?.result
      // Do something with result
      print("The result is... (result)")


      return nil




      However, I don't understand the data structure returned at the Client yet. This is what I get:



      You clicked invoke api...
      The result is... <AmplifyRestApiTest.Empty: 0x600002020770>



      Here are the full contents of the generated <API-Name>Client.swift file (with some comments removed). I'm thinking it's possible that the README is no longer in sync with the SDK generation.



      import AWSCore
      import AWSAPIGateway

      public class SVTLambdaGateClient: AWSAPIGatewayClient {

      static let AWSInfoClientKey = "SVTLambdaGateClient"

      private static let _serviceClients = AWSSynchronizedMutableDictionary()
      private static let _defaultClient:SVTLambdaGateClient =
      var serviceConfiguration: AWSServiceConfiguration? = nil
      let serviceInfo = AWSInfo.default().defaultServiceInfo(AWSInfoClientKey)
      if let serviceInfo = serviceInfo
      serviceConfiguration = AWSServiceConfiguration(region: serviceInfo.region, credentialsProvider: serviceInfo.cognitoCredentialsProvider)
      else if (AWSServiceManager.default().defaultServiceConfiguration != nil)
      serviceConfiguration = AWSServiceManager.default().defaultServiceConfiguration
      else
      serviceConfiguration = AWSServiceConfiguration(region: .Unknown, credentialsProvider: nil)


      return SVTLambdaGateClient(configuration: serviceConfiguration!)
      ()

      /**
      Returns the singleton service client. If the singleton object does not exist, the SDK instantiates the default service client with `defaultServiceConfiguration` from `AWSServiceManager.defaultServiceManager()`. The reference to this object is maintained by the SDK, and you do not need to retain it manually.
      @return The default service client.
      */

      public class func `default`() -> SVTLambdaGateClient
      return _defaultClient


      /**
      Creates a service client with the given service configuration and registers it for the key.
      @param configuration A service configuration object.
      @param key A string to identify the service client.
      */

      public class func registerClient(withConfiguration configuration: AWSServiceConfiguration, forKey key: String)
      _serviceClients.setObject(SVTLambdaGateClient(configuration: configuration), forKey: key as NSString);


      /**
      Retrieves the service client associated with the key. You need to call `registerClient(withConfiguration:configuration, forKey:)` before invoking this method or alternatively, set the configuration in your application's `info.plist` file. If `registerClientWithConfiguration(configuration, forKey:)` has not been called in advance or if a configuration is not present in the `info.plist` file of the app, this method returns `nil`.
      Then call the following to get the service client:

      let serviceClient = SVTLambdaGateClient.client(forKey: "USWest2SVTLambdaGateClient")

      @param key A string to identify the service client.
      @return An instance of the service client.
      */
      public class func client(forKey key: String) -> SVTLambdaGateClient
      objc_sync_enter(self)
      if let client: SVTLambdaGateClient = _serviceClients.object(forKey: key) as? SVTLambdaGateClient
      objc_sync_exit(self)
      return client


      let serviceInfo = AWSInfo.default().defaultServiceInfo(AWSInfoClientKey)
      if let serviceInfo = serviceInfo
      let serviceConfiguration = AWSServiceConfiguration(region: serviceInfo.region, credentialsProvider: serviceInfo.cognitoCredentialsProvider)
      SVTLambdaGateClient.registerClient(withConfiguration: serviceConfiguration!, forKey: key)

      objc_sync_exit(self)
      return _serviceClients.object(forKey: key) as! SVTLambdaGateClient;


      /**
      Removes the service client associated with the key and release it.

      @param key A string to identify the service client.
      */
      public class func removeClient(forKey key: String) -> Void
      _serviceClients.remove(key)


      init(configuration: AWSServiceConfiguration)
      super.init()

      self.configuration = configuration.copy() as! AWSServiceConfiguration
      var URLString: String = "https://<my-api-id>.execute-api.us-east-2.amazonaws.com/test"
      if URLString.hasSuffix("/")
      URLString = URLString.substring(to: URLString.index(before: URLString.endIndex))

      self.configuration.endpoint = AWSEndpoint(region: configuration.regionType, service: .APIGateway, url: URL(string: URLString))
      let signer: AWSSignatureV4Signer = AWSSignatureV4Signer(credentialsProvider: configuration.credentialsProvider, endpoint: self.configuration.endpoint)
      if let endpoint = self.configuration.endpoint
      self.configuration.baseURL = endpoint.url

      self.configuration.requestInterceptors = [AWSNetworkingRequestInterceptor(), signer]


      /*


      @param operand2
      @param _operator
      @param operand1

      return type: Empty
      */
      public func calcGet(operand2: String, _operator: String, operand1: String) -> AWSTask<Empty>
      let headerParameters = [
      "Content-Type": "application/json",
      "Accept": "application/json",

      ]

      var queryParameters:[String:Any] = [:]
      queryParameters["operand2"] = operand2
      queryParameters["operator"] = _operator
      queryParameters["operand1"] = operand1

      let pathParameters:[String:Any] = [:]

      return self.invokeHTTPRequest("GET", urlString: "/calc", pathParameters: pathParameters, queryParameters: queryParameters, headerParameters: headerParameters, body: nil, responseClass: Empty.self) as! AWSTask<Empty>



      /*


      @param body

      return type: Empty
      */
      public func calcPost(body: SVTInput) -> AWSTask<Empty>
      let headerParameters = [
      "Content-Type": "application/json",
      "Accept": "application/json",

      ]

      let queryParameters:[String:Any] = [:]

      let pathParameters:[String:Any] = [:]

      return self.invokeHTTPRequest("POST", urlString: "/calc", pathParameters: pathParameters, queryParameters: queryParameters, headerParameters: headerParameters, body: body, responseClass: Empty.self) as! AWSTask<Empty>



      /*


      @param operand2
      @param _operator
      @param operand1

      return type: SVTResult
      */
      public func calcOperand1Operand2OperatorGet(operand2: String, _operator: String, operand1: String) -> AWSTask<SVTResult>
      let headerParameters = [
      "Content-Type": "application/json",
      "Accept": "application/json",

      ]

      let queryParameters:[String:Any] = [:]

      var pathParameters:[String:Any] = [:]
      pathParameters["operand2"] = operand2
      pathParameters["operator"] = _operator
      pathParameters["operand1"] = operand1

      return self.invokeHTTPRequest("GET", urlString: "/calc/operand1/operand2/operator", pathParameters: pathParameters, queryParameters: queryParameters, headerParameters: headerParameters, body: nil, responseClass: SVTResult.self) as! AWSTask<SVTResult>



      Any help greatly appreciated!







      swift xcode amazon-web-services aws-lambda aws-api-gateway






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Apr 1 at 1:17







      motivus

















      asked Mar 25 at 0:05









      motivusmotivus

      7310




      7310






















          1 Answer
          1






          active

          oldest

          votes


















          0














          The Amplify team (who maintain and develop the AWS iOS SDK) verified that the documentation is incorrect. It should reference default() and not defaultClient().






          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55329768%2fios-sdk-generated-by-aws-api-gateway-is-missing-required-defaultclient-member%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            The Amplify team (who maintain and develop the AWS iOS SDK) verified that the documentation is incorrect. It should reference default() and not defaultClient().






            share|improve this answer



























              0














              The Amplify team (who maintain and develop the AWS iOS SDK) verified that the documentation is incorrect. It should reference default() and not defaultClient().






              share|improve this answer

























                0












                0








                0







                The Amplify team (who maintain and develop the AWS iOS SDK) verified that the documentation is incorrect. It should reference default() and not defaultClient().






                share|improve this answer













                The Amplify team (who maintain and develop the AWS iOS SDK) verified that the documentation is incorrect. It should reference default() and not defaultClient().







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Apr 5 at 1:25









                motivusmotivus

                7310




                7310





























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55329768%2fios-sdk-generated-by-aws-api-gateway-is-missing-required-defaultclient-member%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                    Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

                    Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript