Add a couple of questions and exercises
SSIA
This commit is contained in:
3
exercises/aws/hello_function.md
Normal file
3
exercises/aws/hello_function.md
Normal file
@@ -0,0 +1,3 @@
|
||||
## Hello Function
|
||||
|
||||
Create a basic AWS Lambda function that when given a name, will return "Hello <NAME>"
|
49
exercises/aws/solutions/hello_function.md
Normal file
49
exercises/aws/solutions/hello_function.md
Normal file
@@ -0,0 +1,49 @@
|
||||
## Hello Function - Solution
|
||||
|
||||
### Exercise
|
||||
|
||||
Create a basic AWS Lambda function that when given a name, will return "Hello <NAME>"
|
||||
|
||||
### Solution
|
||||
|
||||
#### Define a function
|
||||
|
||||
1. Go to Lambda console panel and click on `Create function`
|
||||
1. Give the function a name like `BasicFunction`
|
||||
2. Select `Python3` runtime
|
||||
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"
|
||||
4. In "Policy Templates" select "Simple Microservice Permissions"
|
||||
|
||||
1. Next, you should see a text editor where you will insert a code similar to the following
|
||||
|
||||
#### Function's code
|
||||
```
|
||||
import json
|
||||
|
||||
|
||||
def lambda_handler(event, context):
|
||||
firstName = event['name']
|
||||
return 'Hello ' + firstName
|
||||
```
|
||||
2. Click on "Create Function"
|
||||
|
||||
#### Define a test
|
||||
|
||||
1. Now let's test the function. Click on "Test".
|
||||
2. Select "Create new test event"
|
||||
3. Set the "Event name" to whatever you'd like. For example "TestEvent"
|
||||
4. Provide keys to test
|
||||
|
||||
```
|
||||
{
|
||||
"name": 'Spyro'
|
||||
}
|
||||
```
|
||||
5. Click on "Create"
|
||||
|
||||
#### Test the function
|
||||
|
||||
1. Choose the test event you've create (`TestEvent`)
|
||||
2. Click on the `Test` button
|
||||
3. You should see something similar to `Execution result: succeeded`
|
||||
4. If you'll go to AWS CloudWatch, you should see a related log stream
|
71
exercises/aws/solutions/url_function.md
Normal file
71
exercises/aws/solutions/url_function.md
Normal file
@@ -0,0 +1,71 @@
|
||||
## URL Function
|
||||
|
||||
Create a basic AWS Lambda function that will be triggered when you enter a URL in the browser
|
||||
|
||||
### Solution
|
||||
|
||||
#### Define a function
|
||||
|
||||
1. Go to Lambda console panel and click on `Create function`
|
||||
1. Give the function a name like `urlFunction`
|
||||
2. Select `Python3` runtime
|
||||
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"
|
||||
4. In "Policy Templates" select "Simple Microservice Permissions"
|
||||
|
||||
1. Next, you should see a text editor where you will insert a code similar to the following
|
||||
|
||||
#### Function's code
|
||||
```
|
||||
import json
|
||||
|
||||
|
||||
def lambda_handler(event, context):
|
||||
firstName = event['name']
|
||||
return 'Hello ' + firstName
|
||||
```
|
||||
2. Click on "Create Function"
|
||||
|
||||
#### Define a test
|
||||
|
||||
1. Now let's test the function. Click on "Test".
|
||||
2. Select "Create new test event"
|
||||
3. Set the "Event name" to whatever you'd like. For example "TestEvent"
|
||||
4. Provide keys to test
|
||||
|
||||
```
|
||||
{
|
||||
"name": 'Spyro'
|
||||
}
|
||||
```
|
||||
5. Click on "Create"
|
||||
|
||||
#### Test the function
|
||||
|
||||
1. Choose the test event you've create (`TestEvent`)
|
||||
2. Click on the `Test` button
|
||||
3. You should see something similar to `Execution result: succeeded`
|
||||
4. If you'll go to AWS CloudWatch, you should see a related log stream
|
||||
|
||||
#### Define a trigger
|
||||
|
||||
We'll define a trigger in order to trigger the function when inserting the URL in the browser
|
||||
|
||||
1. Go to "API Gateway console" and click on "New API Option"
|
||||
2. Insert the API name, description and click on "Create"
|
||||
3. Click on Action -> Create Resource
|
||||
4. Insert resource name and path (e.g. the path can be /hello) and click on "Create Resource"
|
||||
5. Select the resource we've created and click on "Create Method"
|
||||
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
|
||||
7. Confirm settings and any required permissions
|
||||
8. Now click again on the resource and modify "Body Mapping Templates" so the template includes this:
|
||||
|
||||
```
|
||||
{ "name": "$input.params('name')" }
|
||||
```
|
||||
9. Finally save and click on Actions -> Deploy API
|
||||
|
||||
#### Running the function
|
||||
|
||||
1. In the API Gateway console, in stages menu, select the API we've created and click on the GET option
|
||||
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`
|
||||
3. You should see in your browser `Hello Mario`
|
3
exercises/aws/url_function.md
Normal file
3
exercises/aws/url_function.md
Normal file
@@ -0,0 +1,3 @@
|
||||
## URL Function
|
||||
|
||||
Create a basic AWS Lambda function that will be triggered when you enter a URL in the browser
|
49
exercises/git/solutions/squashing_commits.md
Normal file
49
exercises/git/solutions/squashing_commits.md
Normal file
@@ -0,0 +1,49 @@
|
||||
## Git - Squashing Commits - Solution
|
||||
|
||||
|
||||
1. In a git repository, create a new file with the content "Mario" and commit the change
|
||||
|
||||
```
|
||||
git add new_file
|
||||
echo "Mario" -> new_file
|
||||
git commit -a -m "New file"
|
||||
```
|
||||
|
||||
2. Make change to the content of the file you just created so the content is "Mario & Luigi" and create another commit
|
||||
|
||||
```
|
||||
echo "Mario & Luigi" > new_file
|
||||
git commit -a -m "Added Luigi"
|
||||
```
|
||||
|
||||
3. Verify you have two separate commits - `git log`
|
||||
|
||||
4. Squash the two commits you've created into one commit
|
||||
|
||||
```
|
||||
git rebase -i HEAD~2
|
||||
```
|
||||
|
||||
You should see something similar to:
|
||||
|
||||
```
|
||||
pick 5412076 New file
|
||||
pick 4016808 Added Luigi
|
||||
```
|
||||
|
||||
Change `pick` to `squash`
|
||||
|
||||
|
||||
```
|
||||
pick 5412076 New file
|
||||
squash 4016808 Added Luigi
|
||||
```
|
||||
|
||||
Save it and provide a commit message for the squashed commit
|
||||
|
||||
### After you complete the exercise
|
||||
|
||||
Answer the following:
|
||||
|
||||
* 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.
|
||||
* Is it possible to squash more than 2 commits? - yes
|
19
exercises/git/squashing_commits.md
Normal file
19
exercises/git/squashing_commits.md
Normal file
@@ -0,0 +1,19 @@
|
||||
## Git - Squashing Commits
|
||||
|
||||
### Objective
|
||||
|
||||
Learn how to squash commits
|
||||
|
||||
### Instructions
|
||||
|
||||
1. In a git repository, create a new file with the content "Mario" and create a new commit
|
||||
2. Make change to the content of the file you just created so the content is "Mario & Luigi" and create another commit
|
||||
3. Verify you have two separate commits
|
||||
4. Squash the latest two commits into one commit
|
||||
|
||||
### After you complete the exercise
|
||||
|
||||
Answer the following:
|
||||
|
||||
* What is the reason for squashing commits?
|
||||
* Is it possible to squash more than 2 commits?
|
12
exercises/kubernetes/killing_containers.md
Normal file
12
exercises/kubernetes/killing_containers.md
Normal file
@@ -0,0 +1,12 @@
|
||||
## "Killing" Containers
|
||||
|
||||
1. Run Pod with a web service (e.g. httpd)
|
||||
2. Verify the web service is running with the `ps` command
|
||||
3. Check how many restarts the pod has performed
|
||||
4. Kill the web service process
|
||||
5. Check how many restarts the pod has performed
|
||||
6. Verify again the web service is running
|
||||
|
||||
## After you complete the exercise
|
||||
|
||||
* Why did the "RESTARTS" count raised?
|
12
exercises/kubernetes/solutions/killing_containers.md
Normal file
12
exercises/kubernetes/solutions/killing_containers.md
Normal file
@@ -0,0 +1,12 @@
|
||||
## "Killing" Containers - Solution
|
||||
|
||||
1. Run Pod with a web service (e.g. httpd) - `kubectl run web --image registry.redhat.io/rhscl/httpd-24-rhel7`
|
||||
2. Verify the web service is running with the `ps` command - `kubectl exec web -- ps`
|
||||
3. Check how many restarts the pod has performed - `kubectl get po web`
|
||||
4. Kill the web service process -`kubectl exec web -- kill 1`
|
||||
5. Check how many restarts the pod has performed - `kubectl get po web`
|
||||
6. Verify again the web service is running - `kubectl exec web -- ps`
|
||||
|
||||
## After you complete the exercise
|
||||
|
||||
* 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`
|
Reference in New Issue
Block a user