I am receiving data in CSV file in a specific bucket. I have to load that data in corresponding CloudSQL table. I have following queries on that:
The documentation on importing a CSV into CloudSQL contains this sample of a curl
call:
ACCESS_TOKEN="$(gcloud auth application-default print-access-token)" curl --header "Authorization: Bearer ${ACCESS_TOKEN}" \ --header 'Content-Type: application/json' \ --data '{"importContext": {"fileType": "CSV", "uri": "gs://<BUCKET_NAME>/<PATH_TO_DUMP_FILE>", "database": "<DATABASE_NAME>", "csvImportOptions": {"table": "<TABLE_NAME>"}}}' \ -X POST \ https://www.googleapis.com/sql/v1beta4/projects/[PROJECT-ID]/instances/[INSTANCE_NAME]/import
Some important things to note:
curl
is just a way to perform a HTTP call from the command line. In Cloud Functions you'd perform the equivalent HTTP call from your code, for example with fetch()
in Node.js.ACCESS_TOKEN
might not be needed. If they are needed after all, have a look here: https://www.npmjs.com/package/google-auth-library#application-default-credentials