You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This calls the endpoint 'localhost:80/auth' with the '{"email":"<EMAIL>","password":"<PASSWORD>"}' as the message body. The return value is a jwt token based on the secret you supplied. We are assigning that secret to the environment variable 'TOKEN'. To see the jwt token, run:
46
+
This calls the endpoint 'localhost:80/auth' with the '{"email":"<EMAIL>","password":"<PASSWORD>"}' as the message body. The return value is a jwt token based on the secret you supplied. We are assigning that secret to the environment variable 'TOKEN'. To see the jwt token, run:
47
47
48
-
```bash
48
+
```bash
49
49
echo$TOKEN
50
50
```
51
-
To call the 'contents' endpoint, which decrpyts the token and returns it content, run:
51
+
To call the 'contents' endpoint, which decrpyts the token and returns it content, run:
52
52
53
-
```bash
53
+
```bash
54
54
curl --request GET 'http://127.0.0.1:80/contents' -H "Authorization: Bearer ${TOKEN}"| jq .
55
55
```
56
-
You should see the email that you passed in as one of the values.
56
+
You should see the email that you passed in as one of the values.
2. Create a Docker file. A Docker file decribes how to build a Docker image. Create a file named 'Dockerfile' in the app repo. The contents of the file describe the steps in creating a Docker image. Your Dockerfile should:
62
+
2. Create a Docker file. A Docker file decribes how to build a Docker image. Create a file named 'Dockerfile'in the app repo. The contents of the file describe the steps in creating a Docker image. Your Dockerfile should:
63
63
- use the 'python:strech' image as a source image
64
64
- Setup an app directory for your code
65
65
- Install needed python requirements
66
66
- Define an entrypoint which will run the main app using the gunicorn WSGI server
67
67
68
-
gunicorn should be run with the arguments:
68
+
gunicorn should be run with the arguments:
69
69
70
-
```
70
+
```
71
71
gunicorn -b :8080 main:APP
72
72
```
73
73
74
74
75
75
3. Create a file named 'env_file' and use it to set the environment variables which will be run locally in your container. Here we do not need the export command, just an equals sign:
76
76
77
77
78
-
\<VARIABLE-NAME\>=\<VARIABLE-VALUE\>
78
+
\<VARIABLE-NAME\>=\<VARIABLE-VALUE\>
79
79
80
80
4. Build a Local Docker Image
81
-
To build a Docker image run:
81
+
To build a Docker image run:
82
82
```
83
83
docker build -t jwt-api-test .
84
84
```
85
85
86
86
5. Run the image locally, using the 'gunicorn' server:
87
-
```
87
+
```
88
88
docker run --env-file=env_file -p 80:8080 jwt-api-test
89
89
```
90
90
91
-
To use the endpoints use the same curl commands as before:
91
+
To use the endpoints use the same curl commands as before:
## Deployment to Kubernetes using CodePipeline and CodeBuild
100
101
101
-
### Deploy a Kubernetes Cluster
102
+
### Create a Kubernetes (EKS) Cluster
102
103
103
104
1. Install aws cli
104
105
105
-
```bash
106
+
```bash
106
107
pip install awscli --upgrade --user
107
108
```
108
109
109
-
Note: If you are using a Python virtual environment, the command will be:
110
+
Note: If you are using a Python virtual environment, the command will be:
110
111
111
-
```bash
112
+
```bash
112
113
pip install awscli --upgrade
113
114
```
114
115
115
116
2.
116
117
[Generate a aws access key id and secret key](https://docs.aws.amazon.com/general/latest/gr/aws-sec-cred-types.html#access-keys-and-secret-access-keys)
117
118
118
119
3. Setup your environment to use these keys:
119
-
If you not already have a aws 'credentials' file setup, run:
120
+
If you not already have a aws 'credentials' file setup, run:
120
121
121
-
```bash
122
+
```bash
122
123
aws configure
123
124
```
124
125
And use the credentials you generated in step 2. Your aws commandline tools will now use these credentials.
@@ -128,64 +129,63 @@ And use the credentials you generated in step 2. Your aws commandline tools will
128
129
The 'eksctl' tool allow interaction wth a EKS cluster from the command line. To install, follow the [directions for your platform](https://docs.aws.amazon.com/eks/latest/userguide/eksctl.html)
A Github acces token will allow CodePipeline to monitor when a repo is changed. A token can be generated [here](https://github.com/settings/tokens/=).
172
+
1. Generate a GitHub access token.
173
+
A Github acces token will allow CodePipeline to monitor when a repo is changed. A token can be generated [here](https://github.com/settings/tokens/=).
174
174
This token should be saved somewhere that is secure.
175
175
176
-
10. The file buildspec.yml instructs CodeBuild. We need a way to pass your jwt secret to the app in kubernetes securly. You will be using AWS parameter-store to do this. First add the following to your buildspec.yml file:
176
+
1. The file *buildspec.yml* instructs CodeBuild. We need a way to pass your jwt secret to the app in kubernetes securly. You will be using AWS parameter-store to do this. First add the following to your buildspec.yml file:
177
177
178
-
```yaml
178
+
```yaml
179
179
env:
180
180
parameter-store:
181
181
JWT_SECRET: JWT_SECRET
182
182
```
183
183
184
-
This lets CodeBuild know to set an evironment variable based on a value in the parameter-store.
184
+
This lets CodeBuild know to set an evironment variable based on a value in the parameter-store.
You can check it's status in the [CloudFormation console](https://us-east-2.console.aws.amazon.com/cloudformation/).
211
211
212
-
15. Check the pipeline works. Once the stack is successfully created, commit a change to the master branch of your github repo. Then, in the aws console go to the [CodePipeline UI](https://us-east-2.console.aws.amazon.com/codesuite/codepipeline). You should see that the build is running.
212
+
1. Check the pipeline works. Once the stack is successfully created, commit a change to the master branch of your github repo. Then, in the aws console go to the [CodePipeline UI](https://us-east-2.console.aws.amazon.com/codesuite/codepipeline). You should see that the build is running.
213
213
214
214
16. To test your api endpoints, get the external ip for your service:
0 commit comments