Skip to content

Commit

Permalink
Merge branch 'change-default-stage'
Browse files Browse the repository at this point in the history
* change-default-stage:
  Add feature to changelog
  Rename default stage v1 to api
  Change the default api gateway stage name to v1
  • Loading branch information
jamesls committed Jul 28, 2017
2 parents 2353fc0 + 263cfbb commit 69f18d7
Show file tree
Hide file tree
Showing 12 changed files with 52 additions and 42 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
CHANGELOG
=========

Next Release (TBD)
==================

* Change default API Gateway stage name to ``api``
(`#431 <https://github.com/awslabs/chalice/pull/431>`__)


1.0.0b2
=======

Expand Down
44 changes: 22 additions & 22 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ It provides:

$ chalice deploy
...
Your application is available at: https://endpoint/dev
Your application is available at: https://endpoint/api

$ curl https://endpoint/dev
$ curl https://endpoint/api
{"hello": "world"}

Up and running in less than 30 seconds.
Expand Down Expand Up @@ -176,11 +176,11 @@ directory and run ``chalice deploy``::
$ chalice deploy
...
Initiating first time deployment...
https://qxea58oupc.execute-api.us-west-2.amazonaws.com/dev/
https://qxea58oupc.execute-api.us-west-2.amazonaws.com/api/

You now have an API up and running using API Gateway and Lambda::

$ curl https://qxea58oupc.execute-api.us-west-2.amazonaws.com/dev/
$ curl https://qxea58oupc.execute-api.us-west-2.amazonaws.com/api/
{"hello": "world"}

Try making a change to the returned dictionary from the ``index()``
Expand All @@ -195,7 +195,7 @@ Here's an example of using ``httpie`` to request the root resource of the API
we just created. Note that the command name is ``http``::


$ http https://qxea58oupc.execute-api.us-west-2.amazonaws.com/dev/
$ http https://qxea58oupc.execute-api.us-west-2.amazonaws.com/api/
HTTP/1.1 200 OK
Connection: keep-alive
Content-Length: 18
Expand All @@ -209,10 +209,10 @@ we just created. Note that the command name is ``http``::


Additionally, the API Gateway endpoints will be shortened to
``https://endpoint/dev/`` for brevity. Be sure to substitute
``https://endpoint/dev/`` for the actual endpoint that the ``chalice``
``https://endpoint/api/`` for brevity. Be sure to substitute
``https://endpoint/api/`` for the actual endpoint that the ``chalice``
CLI displays when you deploy your API (it will look something like
``https://abcdefg.execute-api.us-west-2.amazonaws.com/dev/``.
``https://abcdefg.execute-api.us-west-2.amazonaws.com/api/``.

Next Steps
----------
Expand Down Expand Up @@ -278,14 +278,14 @@ the ``helloworld`` directory and it will deploy your application::
Let's try it out. Note the examples below use the ``http`` command
from the ``httpie`` package. You can install this using ``pip install httpie``::

$ http https://endpoint/dev/cities/seattle
$ http https://endpoint/api/cities/seattle
HTTP/1.1 200 OK

{
"state": "WA"
}

$ http https://endpoint/dev/cities/portland
$ http https://endpoint/api/cities/portland
HTTP/1.1 200 OK

{
Expand All @@ -296,7 +296,7 @@ from the ``httpie`` package. You can install this using ``pip install httpie``:
Notice what happens if we try to request a city that's not in our
``CITIES_TO_STATE`` map::

$ http https://endpoint/dev/cities/vancouver
$ http https://endpoint/api/cities/vancouver
HTTP/1.1 500 Internal Server Error
Content-Type: application/json
X-Cache: Error from cloudfront
Expand Down Expand Up @@ -337,12 +337,12 @@ Save this file and redeploy your changes::

$ chalice deploy
...
https://endpoint/dev/
https://endpoint/api/

Now, when you request the same URL that returned an internal
server error, you'll get back the original stack trace::

$ http https://endpoint/dev/cities/vancouver
$ http https://endpoint/api/cities/vancouver
Traceback (most recent call last):
File "/var/task/chalice/app.py", line 304, in _get_view_function_response
response = view_function(*function_args)
Expand Down Expand Up @@ -374,7 +374,7 @@ to the user. Here's the updated code:
Save and deploy these changes::

$ chalice deploy
$ http https://endpoint/dev/cities/vancouver
$ http https://endpoint/api/cities/vancouver
HTTP/1.1 400 Bad Request

{
Expand Down Expand Up @@ -418,7 +418,7 @@ Here's an example of a view function that supports PUT:
We can test this method using the ``http`` command::

$ http PUT https://endpoint/dev/resource/foo
$ http PUT https://endpoint/api/resource/foo
HTTP/1.1 200 OK

{
Expand Down Expand Up @@ -510,7 +510,7 @@ body, and retrieve the value of that body by making a subsequent
``GET`` request to the same resource. Here's an example of its usage::

# First, trying to retrieve the key will return a 404.
$ http GET https://endpoint/dev/objects/mykey
$ http GET https://endpoint/api/objects/mykey
HTTP/1.1 404 Not Found

{
Expand All @@ -519,14 +519,14 @@ body, and retrieve the value of that body by making a subsequent
}

# Next, we'll create that key by sending a PUT request.
$ echo '{"foo": "bar"}' | http PUT https://endpoint/dev/objects/mykey
$ echo '{"foo": "bar"}' | http PUT https://endpoint/api/objects/mykey
HTTP/1.1 200 OK

null

# And now we no longer get a 404, we instead get the value we previously
# put.
$ http GET https://endpoint/dev/objects/mykey
$ http GET https://endpoint/api/objects/mykey
HTTP/1.1 200 OK

{
Expand Down Expand Up @@ -567,7 +567,7 @@ Here's an example of hitting the ``/introspect`` URL. Note how we're
sending a query string as well as a custom ``X-TestHeader`` header::


$ http 'https://endpoint/dev/introspect?query1=value1&query2=value2' 'X-TestHeader: Foo'
$ http 'https://endpoint/api/introspect?query1=value1&query2=value2' 'X-TestHeader: Foo'
HTTP/1.1 200 OK

{
Expand Down Expand Up @@ -653,7 +653,7 @@ First, we've specified that we only accept the
try to send a request with ``application/json``, we'll now
get a ``415 Unsupported Media Type`` response::

$ http POST https://endpoint/dev/ states=WA states=CA --debug
$ http POST https://endpoint/api/ states=WA states=CA --debug
...
>>> requests.request(**{'allow_redirects': False,
'headers': {'Accept': 'application/json',
Expand All @@ -671,7 +671,7 @@ If we use the ``--form`` argument, we can see the
expected behavior of this view function because ``httpie`` sets the
``Content-Type`` header to ``application/x-www-form-urlencoded``::

$ http --form POST https://endpoint/dev/formtest states=WA states=CA --debug
$ http --form POST https://endpoint/api/formtest states=WA states=CA --debug
...
>>> requests.request(**{'allow_redirects': False,
'headers': {'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8',
Expand Down Expand Up @@ -731,7 +731,7 @@ Here's an example of this:
This will result in a plain text response body::

$ http https://endpoint/dev/
$ http https://endpoint/api/
HTTP/1.1 200 OK
Content-Length: 12
Content-Type: text/plain
Expand Down
3 changes: 2 additions & 1 deletion chalice/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from chalice.utils import getting_started_prompt
from chalice.constants import CONFIG_VERSION, TEMPLATE_APP, GITIGNORE
from chalice.constants import DEFAULT_STAGE_NAME
from chalice.constants import DEFAULT_APIGATEWAY_STAGE_NAME


def create_new_project_skeleton(project_name, profile=None):
Expand All @@ -39,7 +40,7 @@ def create_new_project_skeleton(project_name, profile=None):
'app_name': project_name,
'stages': {
DEFAULT_STAGE_NAME: {
'api_gateway_stage': DEFAULT_STAGE_NAME,
'api_gateway_stage': DEFAULT_APIGATEWAY_STAGE_NAME,
}
}
}
Expand Down
1 change: 1 addition & 0 deletions chalice/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def index():
"""

DEFAULT_STAGE_NAME = 'dev'
DEFAULT_APIGATEWAY_STAGE_NAME = 'api'


DEFAULT_LAMBDA_TIMEOUT = 60
Expand Down
4 changes: 2 additions & 2 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ It provides:

$ chalice deploy
...
Your application is available at: https://endpoint/dev
Your application is available at: https://endpoint/api

$ curl https://endpoint/dev
$ curl https://endpoint/api
{"hello": "world"}

Up and running in less than 30 seconds.
Expand Down
6 changes: 3 additions & 3 deletions docs/source/topics/authorizers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ necessary Lambda functions for us.

Now when we try to make a request, we'll get an Unauthorized error::

$ http https://api.us-west-2.amazonaws.com/dev/
$ http https://api.us-west-2.amazonaws.com/api/
HTTP/1.1 401 Unauthorized

{
Expand All @@ -174,7 +174,7 @@ Now when we try to make a request, we'll get an Unauthorized error::

If we add the appropriate authorization header, we'll see the call succeed::

$ http https://api.us-west-2.amazonaws.com/dev/ 'Authorization: allow'
$ http https://api.us-west-2.amazonaws.com/api/ 'Authorization: allow'
HTTP/1.1 200 OK

{
Expand All @@ -199,7 +199,7 @@ If we add the appropriate authorization header, we'll see the call succeed::
"userAgent": "HTTPie/0.9.9",
"userArn": null
},
"path": "/dev/",
"path": "/api/",
"requestId": "d35d2063-56be-11e7-9ce1-dd61c24a3668",
"resourceId": "id",
"resourcePath": "/",
Expand Down
4 changes: 2 additions & 2 deletions docs/source/topics/cfn.rst
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ will be available as an output::

$ aws cloudformation describe-stacks --stack-name test-cfn-stack \
--query "Stacks[].Outputs[?OutputKey=='EndpointURL'][] | [0].OutputValue"
"https://abc29hkq0i.execute-api.us-west-2.amazonaws.com/dev/"
"https://abc29hkq0i.execute-api.us-west-2.amazonaws.com/api/"

$ http "https://abc29hkq0i.execute-api.us-west-2.amazonaws.com/dev/"
$ http "https://abc29hkq0i.execute-api.us-west-2.amazonaws.com/api/"
HTTP/1.1 200 OK
Connection: keep-alive
Content-Length: 18
Expand Down
6 changes: 3 additions & 3 deletions docs/source/topics/pyversion.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ explicitly configure which version of python you want to use. For example::
...
"Runtime":"python3.6"
...
https://rest-api-id.execute-api.us-west-2.amazonaws.com/dev/
https://rest-api-id.execute-api.us-west-2.amazonaws.com/api/


In the example above, we're using python 3.6.1 so chalice automatically
Expand Down Expand Up @@ -71,7 +71,7 @@ For example, suppose you have an existing chalice app that uses python2::
Python 2.7.12
$ chalice deploy
...
https://endpoint/dev
https://endpoint/api

To upgrade the application to use python3, create a python3 virtual environment
and redeploy. When this happens, you will be prompted to confirm the python
Expand All @@ -87,4 +87,4 @@ runtime version changing::
The python runtime will change from python2.7 to python3.6,
would you like to continue? [Y/n]: y
...
https://endpoint/dev
https://endpoint/api
4 changes: 2 additions & 2 deletions docs/source/topics/routing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,13 @@ Here's an example for accessing query string data in a view function:
In the function above, if the user provides a ``?include-greeting=true`` in the
HTTP request, then an additional ``greeting`` key will be returned::

$ http https://endpoint/dev/users/bob
$ http https://endpoint/api/users/bob

{
"name": "bob"
}

$ http https://endpoint/dev/users/bob?include-greeting=true
$ http https://endpoint/api/users/bob?include-greeting=true

{
"greeting": "Hello, bob",
Expand Down
8 changes: 4 additions & 4 deletions docs/source/topics/stages.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Let's say we have a new app::
$ cd myapp
$ chalice deploy
...
https://mmnkdi.execute-api.us-west-2.amazonaws.com/dev/
https://mmnkdi.execute-api.us-west-2.amazonaws.com/api/

We've just created our first stage, ``dev``. We can iterate on our
application and continue to run ``chalice deploy`` to deploy our code
Expand All @@ -43,15 +43,15 @@ To do this, we can run::

$ chalice deploy --stage prod
...
https://wk9fhx.execute-api.us-west-2.amazonaws.com/dev/
https://wk9fhx.execute-api.us-west-2.amazonaws.com/api/

We now have two completely separate rest APIs::

$ chalice url --stage dev
https://mmnkdi.execute-api.us-west-2.amazonaws.com/dev/
https://mmnkdi.execute-api.us-west-2.amazonaws.com/api/

$ chalice url --stage prod
https://wk9fhx.execute-api.us-west-2.amazonaws.com/dev/
https://wk9fhx.execute-api.us-west-2.amazonaws.com/api/

Additionally, we can see all our deployed values by looking
at the ``.chalice/deployed.json`` file::
Expand Down
4 changes: 2 additions & 2 deletions docs/source/topics/views.rst
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ was instantiated. For example:
This view function will generate the following HTTP response::

$ http https://endpoint/dev/badrequest
$ http https://endpoint/api/badrequest
HTTP/1.1 400 Bad Request

{
Expand Down Expand Up @@ -152,7 +152,7 @@ supports PUT:
We can test this method using the ``http`` command::

$ http PUT https://endpoint/dev/resource/foo
$ http PUT https://endpoint/api/resource/foo
HTTP/1.1 200 OK

{
Expand Down
3 changes: 2 additions & 1 deletion tests/functional/cli/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from chalice.config import Config
from chalice.utils import record_deployed_values
from chalice import local
from chalice.constants import DEFAULT_APIGATEWAY_STAGE_NAME


@pytest.fixture
Expand Down Expand Up @@ -93,7 +94,7 @@ def test_can_load_project_config_after_project_creation(runner):
'version': '2.0',
'app_name': 'testproject',
'stages': {
'dev': {'api_gateway_stage': u'dev'}
'dev': {'api_gateway_stage': DEFAULT_APIGATEWAY_STAGE_NAME},
}
}

Expand Down

0 comments on commit 69f18d7

Please sign in to comment.