All of the cloud infrastructure for this application is provided by Google Cloud Platform.
At a high level, the required cloud infrastructure for this application includes
- A GCP storage bucket. This serves as a persistant data store for application data.
- A GCP cloud function. The API that services client requests is serverless. When invoked it interprets users requests and makes modifications to objects in the storage bucket.
Developers will need to do the following
- Setup a GCloud Account.
- Ensure that you enable billing for your account. GCloud gives new users $300 in free credits so you won't actually be charged unless you surpass this amount of credit, which is hard to do.
- Create a project within your GCloud account for developing this application.
- Install and authenticate the GCloud CLI.
Note: Use the project created above for all GCP console and GCP client library interactions.
These steps create a publically accessible storage bucket. Anyone with the URL can view it's contents.
- Go to
Cloud Storageand thenbuckets. - Create a bucket with
- Region:
us-east1 - Storage Class:
default - Public Access:
Public to internet - Access Control:
Uniform
- Region:
- Go to the bucket's permission settings and add a new IAM permission.
- Principal:
allUsers - Role:
Storage Object Viewer
- Principal:
- Enter the google cloud shell
- Run
nano cors.jsonamd paste in the value contained incors.jsonin this repo. - Run
gsutil cors set cors.json gs://BUCKET_NAME. This ensures that bucket resources are accessible from any origin.
- Run
To run the application, you should create three buckets (all following this same process).
- A testing bucket, used for unit tests.
- A dev bucket, used during development while testing new features and bug fixes.
- A prod bucket, used as the production backend for the application.
Test that everything is working by uploading a test file to the bucket, then using the bucket's public url (with the file name appended) to view the contents.
These steps create a service account with permission to manage (read + write) objects within the bucket created earlier. The google cloud function that we will create in a later step will use assume the identity of this service account to manage objects in the bucket.
- Go to
IAM & Adminand thenService Accounts.- Create a new service account.
- Generate and download a key for this service account (a JSON file).
- Move this file to two locations in the project (will streamline later)
- Root directory
serverlessdirectory.
- Go to the bucket's permission settings and add a new IAM permission.
- Principal:
SERVICE_ACCOUNT_ID(the id of the service account created in step 1). - Role:
Storage Object Admin.
- Principal:
Repeat step 2 for all buckets (dev, testing, prod).
Add the following IAM role to the service account that the cloud function will run as.
- Principal: ID for App Engine default service account.
- Role:
Service Account User.