Skip to content

Commit ab61a49

Browse files
author
abregman
committed
Add a couple of questions and exercises
SSIA
1 parent 0f0167a commit ab61a49

File tree

9 files changed

+473
-64
lines changed

9 files changed

+473
-64
lines changed

README.md

+255-64
Large diffs are not rendered by default.

exercises/aws/hello_function.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## Hello Function
2+
3+
Create a basic AWS Lambda function that when given a name, will return "Hello <NAME>"
+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
## Hello Function - Solution
2+
3+
### Exercise
4+
5+
Create a basic AWS Lambda function that when given a name, will return "Hello <NAME>"
6+
7+
### Solution
8+
9+
#### Define a function
10+
11+
1. Go to Lambda console panel and click on `Create function`
12+
1. Give the function a name like `BasicFunction`
13+
2. Select `Python3` runtime
14+
3. Now to handle function's permissions, we can attach IAM role to our function either by setting a role or creating a new role. I selected "Create a new role from AWS policy templates"
15+
4. In "Policy Templates" select "Simple Microservice Permissions"
16+
17+
1. Next, you should see a text editor where you will insert a code similar to the following
18+
19+
#### Function's code
20+
```
21+
import json
22+
23+
24+
def lambda_handler(event, context):
25+
firstName = event['name']
26+
return 'Hello ' + firstName
27+
```
28+
2. Click on "Create Function"
29+
30+
#### Define a test
31+
32+
1. Now let's test the function. Click on "Test".
33+
2. Select "Create new test event"
34+
3. Set the "Event name" to whatever you'd like. For example "TestEvent"
35+
4. Provide keys to test
36+
37+
```
38+
{
39+
"name": 'Spyro'
40+
}
41+
```
42+
5. Click on "Create"
43+
44+
#### Test the function
45+
46+
1. Choose the test event you've create (`TestEvent`)
47+
2. Click on the `Test` button
48+
3. You should see something similar to `Execution result: succeeded`
49+
4. If you'll go to AWS CloudWatch, you should see a related log stream
+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
## URL Function
2+
3+
Create a basic AWS Lambda function that will be triggered when you enter a URL in the browser
4+
5+
### Solution
6+
7+
#### Define a function
8+
9+
1. Go to Lambda console panel and click on `Create function`
10+
1. Give the function a name like `urlFunction`
11+
2. Select `Python3` runtime
12+
3. Now to handle function's permissions, we can attach IAM role to our function either by setting a role or creating a new role. I selected "Create a new role from AWS policy templates"
13+
4. In "Policy Templates" select "Simple Microservice Permissions"
14+
15+
1. Next, you should see a text editor where you will insert a code similar to the following
16+
17+
#### Function's code
18+
```
19+
import json
20+
21+
22+
def lambda_handler(event, context):
23+
firstName = event['name']
24+
return 'Hello ' + firstName
25+
```
26+
2. Click on "Create Function"
27+
28+
#### Define a test
29+
30+
1. Now let's test the function. Click on "Test".
31+
2. Select "Create new test event"
32+
3. Set the "Event name" to whatever you'd like. For example "TestEvent"
33+
4. Provide keys to test
34+
35+
```
36+
{
37+
"name": 'Spyro'
38+
}
39+
```
40+
5. Click on "Create"
41+
42+
#### Test the function
43+
44+
1. Choose the test event you've create (`TestEvent`)
45+
2. Click on the `Test` button
46+
3. You should see something similar to `Execution result: succeeded`
47+
4. If you'll go to AWS CloudWatch, you should see a related log stream
48+
49+
#### Define a trigger
50+
51+
We'll define a trigger in order to trigger the function when inserting the URL in the browser
52+
53+
1. Go to "API Gateway console" and click on "New API Option"
54+
2. Insert the API name, description and click on "Create"
55+
3. Click on Action -> Create Resource
56+
4. Insert resource name and path (e.g. the path can be /hello) and click on "Create Resource"
57+
5. Select the resource we've created and click on "Create Method"
58+
6. For "integration type" choose "Lambda Function" and insert the lambda function name we've given to the function we previously created. Make sure to also use the same region
59+
7. Confirm settings and any required permissions
60+
8. Now click again on the resource and modify "Body Mapping Templates" so the template includes this:
61+
62+
```
63+
{ "name": "$input.params('name')" }
64+
```
65+
9. Finally save and click on Actions -> Deploy API
66+
67+
#### Running the function
68+
69+
1. In the API Gateway console, in stages menu, select the API we've created and click on the GET option
70+
2. You'll see an invoke URL you can click on. You might have to modify it to include the input so it looks similar to this: `.../hello?name=mario`
71+
3. You should see in your browser `Hello Mario`

exercises/aws/url_function.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## URL Function
2+
3+
Create a basic AWS Lambda function that will be triggered when you enter a URL in the browser
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
## Git - Squashing Commits - Solution
2+
3+
4+
1. In a git repository, create a new file with the content "Mario" and commit the change
5+
6+
```
7+
git add new_file
8+
echo "Mario" -> new_file
9+
git commit -a -m "New file"
10+
```
11+
12+
2. Make change to the content of the file you just created so the content is "Mario & Luigi" and create another commit
13+
14+
```
15+
echo "Mario & Luigi" > new_file
16+
git commit -a -m "Added Luigi"
17+
```
18+
19+
3. Verify you have two separate commits - `git log`
20+
21+
4. Squash the two commits you've created into one commit
22+
23+
```
24+
git rebase -i HEAD~2
25+
```
26+
27+
You should see something similar to:
28+
29+
```
30+
pick 5412076 New file
31+
pick 4016808 Added Luigi
32+
```
33+
34+
Change `pick` to `squash`
35+
36+
37+
```
38+
pick 5412076 New file
39+
squash 4016808 Added Luigi
40+
```
41+
42+
Save it and provide a commit message for the squashed commit
43+
44+
### After you complete the exercise
45+
46+
Answer the following:
47+
48+
* What is the reason for squashing commits? - history becomes cleaner and it's easier to track changes without commit like "removed a character" for example.
49+
* Is it possible to squash more than 2 commits? - yes

exercises/git/squashing_commits.md

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
## Git - Squashing Commits
2+
3+
### Objective
4+
5+
Learn how to squash commits
6+
7+
### Instructions
8+
9+
1. In a git repository, create a new file with the content "Mario" and create a new commit
10+
2. Make change to the content of the file you just created so the content is "Mario & Luigi" and create another commit
11+
3. Verify you have two separate commits
12+
4. Squash the latest two commits into one commit
13+
14+
### After you complete the exercise
15+
16+
Answer the following:
17+
18+
* What is the reason for squashing commits?
19+
* Is it possible to squash more than 2 commits?
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
## "Killing" Containers
2+
3+
1. Run Pod with a web service (e.g. httpd)
4+
2. Verify the web service is running with the `ps` command
5+
3. Check how many restarts the pod has performed
6+
4. Kill the web service process
7+
5. Check how many restarts the pod has performed
8+
6. Verify again the web service is running
9+
10+
## After you complete the exercise
11+
12+
* Why did the "RESTARTS" count raised?
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
## "Killing" Containers - Solution
2+
3+
1. Run Pod with a web service (e.g. httpd) - `kubectl run web --image registry.redhat.io/rhscl/httpd-24-rhel7`
4+
2. Verify the web service is running with the `ps` command - `kubectl exec web -- ps`
5+
3. Check how many restarts the pod has performed - `kubectl get po web`
6+
4. Kill the web service process -`kubectl exec web -- kill 1`
7+
5. Check how many restarts the pod has performed - `kubectl get po web`
8+
6. Verify again the web service is running - `kubectl exec web -- ps`
9+
10+
## After you complete the exercise
11+
12+
* Why did the "RESTARTS" count raised? - `because we killed the process and Kubernetes identified the container isn't running proprely so it performed restart to the Pod`

0 commit comments

Comments
 (0)