0

I am building an app for the first time and it requires a back-end connection with the database. I've established a working EC2 and RDS instance in AWS (also trying out for the first time). I don't know how exactly to establish a connection in Xcode with a .php file, there's a couple missing holes in my knowledge that I hope someone can clear up. Every online resource I've looked up doesn't use the exact stack that I'm using so I get confused as to where to go from here.

How would I go about connecting to my Amazon RDS (mySQL) credentials inside my XCode project? Also would I save a separate .php file with the server connection and insert the URL of the file from my local directory? I know I have an endpoint URL provided by RDS, I'm just confused as to how to go about connecting all of this in order to start the POST/GET requests. There isn't a clear tutorial on this, so hope to get some answers here.

Cœur
  • 37,241
  • 25
  • 195
  • 267

1 Answers1

5

The reason why you can not find tutorial on this subject is because it is not considered a good architecture practice to connect backend databases directly from mobile applications. Not only you have the problem of providing the mobile application with the database credentials, in a secure way, but also it would oblige you to implement the access and authorization logic in your mobile app and will create a hard dependency between your mobile and the database endpoint. What if it crashes ? What if you need more CPU/Storage on the server side to accommodate client requests etc ..

The correct architecture is to expose the data required by your mobile app through a API. AWS has several options to let you create an API (API Gateway and AppSync). In both cases, the amplify command line will generate the XCode Swift code for you for easy integration with your app.

See https://docs.aws.amazon.com/apigateway/latest/developerguide/how-to-generate-sdk-ios-swift.html

See an iOS code sample here https://github.com/sebsto/reinvent2018-mob320 (it doe snot have RDS integration in the backend, I will leave this as an exercise for you)

Searching the web, you will find other persons having post similar questions and having received similar answers :

Sébastien Stormacq
  • 14,301
  • 5
  • 41
  • 64