Skip to content
This repository was archived by the owner on Jan 14, 2025. It is now read-only.

Commit 7b24b97

Browse files
authored
Merge pull request #154 from sliedig/sliedig-patch-1
Updates to DevOps Module 1: Serverless Application Model README
2 parents 7d3b138 + 5f2f6f8 commit 7b24b97

File tree

1 file changed

+30
-36
lines changed

1 file changed

+30
-36
lines changed

DevOps/1_ServerlessApplicationModel/README.md

Lines changed: 30 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
# Module 1: Serverless Application Model
22

3-
In this module you'll learn about the [Serverless Application Model (SAM)](https://github.com/awslabs/serverless-application-model) and how you can use it to define a serverless RESTful API. You will also use [SAM Local](http://docs.aws.amazon.com/lambda/latest/dg/test-sam-local.html) to locally develop and rapidly test an API.
4-
5-
3+
In this module you'll learn about the [Serverless Application Model (SAM)](https://github.com/awslabs/serverless-application-model) and how you can use it to define a serverless RESTful API. You will also use [SAM CLI](http://docs.aws.amazon.com/lambda/latest/dg/test-sam-local.html) to locally develop and rapidly test an API.
64

75
## Serverless Application Model (SAM) Overview
86

@@ -18,7 +16,6 @@ The Unicorn API includes Amazon API Gateway HTTP endpoints that trigger AWS Lamb
1816

1917
In this module, you will be working with a Lambda function that simply displays a welcome message. The Unicorn API components are defined in the [template.yml](uni-api/template.yml) SAM template. Next we'll review the Lambda function component in more detail.
2018

21-
2219
### AWS::Serverless::Function
2320

2421
Below is a code snippet from the SAM template to list Unicorns:
@@ -116,51 +113,50 @@ git fetch --all
116113
git reset --hard origin/master
117114
```
118115

116+
## AWS SAM CLI
119117

120-
## SAM Local
121-
122-
[SAM Local](http://docs.aws.amazon.com/lambda/latest/dg/test-sam-local.html) is the AWS CLI tool for managing Serverless applications written with [Serverless Application Model (SAM)](https://github.com/awslabs/serverless-application-model). SAM Local can be used to test functions locally, start a local API Gateway from a SAM template, validate a SAM template, and generate sample payloads for various event sources.
118+
[AWS SAM CLI](https://docs.aws.amazon.com/lambda/latest/dg/test-sam-cli.html) is the AWS CLI tool for managing Serverless applications written with [Serverless Application Model (SAM)](https://github.com/awslabs/serverless-application-model). SAM CLI can be used to test functions locally, start a local API Gateway from a SAM template, validate a SAM template, and generate sample payloads for various event sources.
123119

124120
### Installation
125121

126-
To complete this module, you will need to install SAM Local. If you already have SAM Local installed, you can skip this section.
122+
To complete this module, you will need to install SAM CLI. If you already have SAM CLI installed, you can skip this section.
127123

128124
#### Prerequisites
129125

130-
Running Serverless projects and functions locally with SAM Local requires Docker to be installed and running. SAM Local will use the `DOCKER_HOST` environment variable to contact the docker daemon.
126+
Running Serverless projects and functions locally with SAM CLI requires Docker to be installed and running. SAM CLI will use the `DOCKER_HOST` environment variable to contact the docker daemon.
127+
128+
* macOS: [Docker for Mac](https://store.docker.com/editions/community/docker-ce-desktop-mac)
129+
* Windows: [Docker Toolbox](https://download.docker.com/win/stable/DockerToolbox.exe)
130+
* Linux: Check your distro's package manager (e.g. yum install docker)
131131

132-
- macOS: [Docker for Mac](https://store.docker.com/editions/community/docker-ce-desktop-mac)
133-
- Windows: [Docker Toolbox](https://download.docker.com/win/stable/DockerToolbox.exe)
134-
- Linux: Check your distro's package manager (e.g. yum install docker)
132+
For macOS and Windows users: SAM CLI requires that the project directory (or any parent directory) is listed in Docker file sharing options.
135133

136-
For macOS and Windows users: SAM local requires that the project directory (or any parent directory) is listed in Docker file sharing options.
134+
Verify that docker is working, and that you can run docker commands from the CLI (e.g. `docker ps`). You do not need to install/fetch/pull any containers - SAM CLI will do it automatically as required.
137135

138-
Verify that docker is working, and that you can run docker commands from the CLI (e.g. `docker ps`). You do not need to install/fetch/pull any containers - SAM Local will do it automatically as required.
139136

137+
#### Windows, Linux, macOS with pip [Recommended]
140138

141-
#### Windows, Linux, macOS with NPM [Recommended]
139+
The easiest way to install **`sam`** is to use [pip](https://pypi.org/project/pip/).
142140

143-
The easiest way to install **`sam`** is to use [NPM](https://www.npmjs.com).
141+
To use pip, you must have [Python](https://www.python.org/) installed and added to your system's Environment path.
144142

145143
```bash
146-
npm install -g aws-sam-local
144+
pip install aws-sam-cli
147145
```
148146

149-
If you get a permission error when using npm (such as `EACCES: permission denied`), please see the instructions on this page of the NPM documentation: [https://docs.npmjs.com/getting-started/fixing-npm-permissions](https://docs.npmjs.com/getting-started/fixing-npm-permissions).
150-
151147
Verify the installation worked:
148+
152149
```bash
153150
sam --version
154151
```
155152

156153
#### Binary release
157154

158-
We also release the CLI as binaries that you can download and instantly use. You can find them under [Releases](https://github.com/awslabs/aws-sam-local/releases) in the SAM Local repo.
159-
155+
We also release the CLI as binaries that you can download and instantly use. You can find them under [Releases](https://github.com/awslabs/aws-sam-cli/releases) in the SAM CLI repo.
160156

161157
#### Alternative Installation: Amazon Linux (EC2)
162158

163-
If you're unable to install SAM Local on your workstation, you may find it easier to use SAM Local on an Amazon Linux EC2 instance. In this case, you will not be performing work locally on your laptop, instead you will connect remotely into an EC2 instance to perform editing and testing.
159+
If you're unable to install SAM CLI on your workstation, you may find it easier to use SAM CLI on an Amazon Linux EC2 instance. In this case, you will not be performing work locally on your laptop, instead you will connect remotely into an EC2 instance to perform editing and testing.
164160

165161
1. [Create a keypair](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-key-pairs.html), if you do not have one already.
166162

@@ -182,19 +178,19 @@ If you're unable to install SAM Local on your workstation, you may find it easie
182178

183179
1. The Git repository has been cloned to the home directory on launch, `/home/ec2-user/uni-api`.
184180

185-
###### Setup Port Forwarding Configuration
181+
##### Setup Port Forwarding Configuration
186182

187-
SAM Local can start an HTTP server locally on EC2 instance on port 3000. In order to view content on that HTTP server through the browser on your laptop, you need to configure port forwarding.
183+
SAM CLI can start an HTTP server locally on EC2 instance on port 3000. In order to view content on that HTTP server through the browser on your laptop, you need to configure port forwarding.
188184

189-
###### Port Forwarding on MacOS
185+
##### Port Forwarding on MacOS
190186

191187
On your workstation, open a new terminal and run the following command. In the command, replace ***~/mykeypair.pem*** with the location and file name of your .pem file and replace ***ec2-###-##-##-###.compute-1.amazonaws.com*** with the public DNS name of your EC2 developer instance:
192188

193189
```
194190
ssh -i ~/mykeypair.pem -N -L 3000:localhost:3000 ec2-user@ec2-###-##-##-###.compute-1.amazonaws.com
195191
```
196192
197-
###### Port Forwarding with Putty on Windows
193+
##### Port Forwarding with Putty on Windows
198194
199195
1. In your putty configuration, select **Connection** , **SSH** , **Tunnels** and add a mapping:
200196
@@ -208,8 +204,7 @@ On your workstation, open a new terminal and run the following command. In the
208204
209205
![Putty Tunnel Config](images/putty-tunnel-config.png)
210206
211-
212-
###### Port Forwarding with Bitvise SSH Client on Windows
207+
##### Port Forwarding with Bitvise SSH Client on Windows
213208
214209
1. In **Profile** window, select **C2S** tab, create an entry with this configuration:
215210
@@ -227,10 +222,9 @@ On your workstation, open a new terminal and run the following command. In the
227222
228223
![Bitvise Tunnel Config](images/bitvise-tunnel-config.png)
229224
225+
## SAM CLI Development
230226
231-
## SAM Local Development
232-
233-
In this section, you will use SAM Local on your workstation to run the Unicorn API and test changes to it without having to deploy to AWS.
227+
In this section, you will use SAM CLI on your workstation to run the Unicorn API and test changes to it without having to deploy to AWS.
234228
235229
### Run API Gateway locally
236230
@@ -248,17 +242,17 @@ In this section, you will use SAM Local on your workstation to run the Unicorn A
248242

249243
This will spawn a local API Gateway to test HTTP request/response functionality. Features hot-reloading to allow you to quickly develop, and iterate over your functions. **`sam`** will automatically find any functions within your SAM template that have `Api` event sources defined, and mount them at the defined HTTP paths.
250244

251-
If this is your first time running SAM Local, there will be a delay as the Docker images are downloaded. Once successful, you should see output similar to the screenshot below:
245+
If this is your first time running SAM CLI, there will be a delay as the Docker images are downloaded. Once successful, you should see output similar to the screenshot below:
252246

253247
![start-api output](images/start-api-output.png)
254248

255249
1. Open a browser and enter `http://127.0.0.1:3000/unicorns` in the address bar. Confirm that you see the output below:
256250

257251
![Hello World in Browser](images/browser-hello-world.png)
258252

259-
Congratulations! You have successfully used SAM Local to start a local development environment. Keep the window open that is running the `sam local start-api` command until this module is complete.
253+
Congratulations! You have successfully used SAM CLI to start a local development environment. Keep the window open that is running the `sam local start-api` command until this module is complete.
260254

261-
Next, let's look at how you can use SAM Local to test changes to your API.
255+
Next, let's look at how you can use SAM CLI to test changes to your API.
262256

263257
### Test code changes locally
264258

@@ -279,9 +273,9 @@ HOW TO update code and verify results (expand for details)
279273
</details>
280274
<p>
281275

282-
Congratulations! You've successfully test changes to a Lambda function in a local development environment. You may now kill the SAM Local running process.
276+
Congratulations! You've successfully test changes to a Lambda function in a local development environment. You may now kill the SAM CLI running process.
283277

284-
To learn more about development with SAM Local, check out [AWS Documentation](http://docs.aws.amazon.com/lambda/latest/dg/test-sam-local.html) and SAM Local [GitHub repository](https://github.com/awslabs/aws-sam-local).
278+
To learn more about development with SAM CLI, check out [AWS Documentation](http://docs.aws.amazon.com/lambda/latest/dg/test-sam-local.html) and SAM CLI [GitHub repository](https://github.com/awslabs/aws-sam-local).
285279

286280
## Completion
287281

0 commit comments

Comments
 (0)