# Deploying to AWS

{% embed url="<https://github.com/FurlanLuka/microservice-stack-shop-demo/pull/12>" %}

For general deployment instructions please follow guide on [Cloud deployment (AWS)](/introduction/deployment/cloud-deployment-aws.md).

### Setting secrets

If you followed the guide above, the Kubernetes cluster should be setup and applications deployed via the CI. The applications will not work until you set the environment variables.

To add environment variables to the deployment, we first have to add cluster secrets. We can do that by using the `kubectl` command.

If you opted for `output_secrets` option when setting up the infrastructure, the database credentials should be located in the `infrastructure/cloud/outputs` folder.

```
kubectl create secret generic auth --from-literal=authentication-secret=secret

kubectl create secret generic queue \
    --from-literal=url=amqp://guest:guest@rabbitmq.default.svc.cluster.local:5672/

kubectl create secret generic redis \
    --from-literal=url=redis://redis-master.default.svc.cluster.local:6379/

kubectl create secret generic database \
    --from-literal=database=<database> \
    --from-literal=username=<user> \
    --from-literal=password=<password> \
    --from-literal=port=<port> \
    --from-literal=hostname=<hostname without port>
```

When the cluster secrets are set, we can apply the environment variables to service deployments by editing `deployment-values.yaml` file, located inside the service folder.

```yaml
secrets:
  enabled: true
  env:
    - name: AUTHENTICATION_SECRET
      valueFrom:
        secretKeyRef:
          name: auth
          key: authentication-secret
    - name: QUEUE_URL
      valueFrom:
        secretKeyRef:
          name: queue
          key: url
    - name: REDIS_URL
      valueFrom:
        secretKeyRef:
          name: redis
          key: url
    - name: TYPEORM_DATABASE
      valueFrom:  
        secretKeyRef:
          name: database
          key: database
    - name: TYPEORM_HOST
      valueFrom:
        secretKeyRef:
          name: database
          key: hostname
    - name: TYPEORM_PASSWORD
      valueFrom:
        secretKeyRef:
          name: database
          key: password
    - name: TYPEORM_PORT
      valueFrom:
        secretKeyRef:
          name: database
          key: port
    - name: TYPEORM_USERNAME
      valueFrom:
        secretKeyRef:
          name: database
          key: username
```

With the secrets added for all 3 services, we can now re-deploy the application by tagging the branch. After the deployment is done, the services should have status Running!

You can now test the API by using the `api.<your domain>` url.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.microservice-stack.com/introduction/demo-project/deploying-to-aws.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
