Amazon Web Services (AWS) - List Serverless Application Model (SAM) endpoints using the sam list endpoints command

by
Jeremy Canfield |
Updated: November 06 2023
| Amazon Web Services (AWS) articles
This assumes you have already:
- Downloaded and Installed the AWS Serverless Application Model (SAM) CLI on Linux.
- Initialize Serverless Application Model (SAM) app using the sam init command
- Built your Serverless Application Model (SAM) app using the sam build command
- Deployed Serverless Application Model (SAM) app using the sam deploy command
Let's say the template.yaml file for your SAM app is located at /tmp/sam-app/template.yaml.
]$ ll /tmp/sam-app
total 20
drwxrwxr-x 2 ec2-user ec2-user 24 Nov 16 02:13 events
drwxrwxr-x 2 ec2-user ec2-user 63 Nov 16 02:13 myapp
-rw-rw-r-- 1 ec2-user ec2-user 0 Nov 16 02:13 __init__.py
-rw-rw-r-- 1 ec2-user ec2-user 8329 Nov 16 02:13 README.md
-rw-rw-r-- 1 ec2-user ec2-user 679 Nov 16 02:13 samconfig.toml
-rw-rw-r-- 1 ec2-user ec2-user 1681 Nov 16 02:13 template.yaml
drwxrwxr-x 4 ec2-user ec2-user 80 Nov 16 02:13 tests
The sam list endpoints command should return both the /Prod and /Stage URLs of your Serverless Application Model (SAM) apps.
]$ sam list endpoints --template /tmp/sam-app/template.yaml --output json
[
{
"LogicalResourceId": "myFunction",
"PhysicalResourceId": "sam-app-myFunction-MgYCNMibayEZ",
"CloudEndpoint": "-",
"Methods": "-"
},
{
"LogicalResourceId": "ServerlessRestApi",
"PhysicalResourceId": "zulgntw90l",
"CloudEndpoint": [
"https://abcdefg123.execute-api.us-east-1.amazonaws.com/Prod",
"https://abcdefg123.execute-api.us-east-1.amazonaws.com/Stage"
],
"Methods": [
"/api/v1['get']"
]
}
]
curl can be used to submit a GET request to the /Prod and /Stage URLs and JSON "hello world" should be returned.
~]$ curl --request GET --url https://zulgntw90l.execute-api.us-east-1.amazonaws.com/Stage/hello
{"message": "hello world"}
~]$ curl --request GET --url https://zulgntw90l.execute-api.us-east-1.amazonaws.com/Prod/hello
{"message": "hello world"}
Did you find this article helpful?
If so, consider buying me a coffee over at