# Writing to a file in App Engine

Assuming your Google Cloud project name is **projectABC**, and you have created an App Engine project, goto IAM, [https://console.cloud.google.com/iam-admin/iam?project=projectABC](https://console.cloud.google.com/iam-admin/iam?project=projectABC)

Click on Grant Access

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1718078269556/1c1a086e-ef0f-46d9-b6a2-e58546b1cbda.png align="center")

Under "Add Principals" add [projectABC@appspot.gserviceaccount.com](mailto:projectABC@appspot.gserviceaccount.com) and assign a role of **Environment and Storage Object Administrator**.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1718078462023/b76d474c-f0b6-40f9-9b4d-738fb4e034e3.png align="center")

Now goto [https://console.cloud.google.com/storage/browser?project=projectABC](https://console.cloud.google.com/storage/browser?project=projectABC) Create a bucket, say, **ABCBucket**, and click Grant Access and Under "Add Principals" add [projectABC@appspot.gserviceaccount.com](mailto:projectABC@appspot.gserviceaccount.com) and assign a role of **Storage Admin**.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1718079495526/c77706c0-ea05-4a78-aad4-36e68bcb96f2.png align="center")

Now you would be able to write to files in Google Storage bucket files directly automatically. Since its' Google App Engine that's writing to Google Storage, there's no need to setup any credentials in the python code.

```python
from google.cloud import storage

def write_to_cloud(your_string):
    client = storage.Client()
    bucket = client.get_bucket('ABCBucket')
    blob = bucket.blob('when-log.txt')
    blob.upload_from_string(your_string)

write_to_cloud("When : " + str(datetime.datetime.now()) + "\n")
```

That's all there is to it !
