Giter VIP home page Giter VIP logo

chalice's Introduction

AWS Chalice

Gitter

Documentation Status

Chalice Logo

Chalice is a framework for writing serverless apps in python. It allows you to quickly create and deploy applications that use AWS Lambda. It provides:

  • A command line tool for creating, deploying, and managing your app
  • A decorator based API for integrating with Amazon API Gateway, Amazon S3, Amazon SNS, Amazon SQS, and other AWS services.
  • Automatic IAM policy generation

You can create Rest APIs:

from chalice import Chalice

app = Chalice(app_name="helloworld")

@app.route("/")
def index():
    return {"hello": "world"}

Tasks that run on a periodic basis:

from chalice import Chalice, Rate

app = Chalice(app_name="helloworld")

# Automatically runs every 5 minutes
@app.schedule(Rate(5, unit=Rate.MINUTES))
def periodic_task(event):
    return {"hello": "world"}

You can connect a lambda function to an S3 event:

from chalice import Chalice

app = Chalice(app_name="helloworld")

# Whenever an object is uploaded to 'mybucket'
# this lambda function will be invoked.

@app.on_s3_event(bucket='mybucket')
def handler(event):
    print("Object uploaded for bucket: %s, key: %s"
          % (event.bucket, event.key))

As well as an SQS queue:

from chalice import Chalice

app = Chalice(app_name="helloworld")

# Invoke this lambda function whenever a message
# is sent to the ``my-queue-name`` SQS queue.

@app.on_sqs_message(queue='my-queue-name')
def handler(event):
    for record in event:
        print("Message body: %s" % record.body)

And several other AWS resources.

Once you've written your code, you just run chalice deploy and Chalice takes care of deploying your app.

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

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

Up and running in less than 30 seconds. Give this project a try and share your feedback with us here on Github.

The documentation is available here.

Quickstart

In this tutorial, you'll use the chalice command line utility to create and deploy a basic REST API. This quickstart uses Python 3.7, but AWS Chalice supports all versions of python supported by AWS Lambda, which includes Python 3.7 through python 3.12.

You can find the latest versions of python on the Python download page.

To install Chalice, we'll first create and activate a virtual environment in python3.7:

$ python3 --version
Python 3.7.3
$ python3 -m venv venv37
$ . venv37/bin/activate

Next we'll install Chalice using pip:

$ python3 -m pip install chalice

You can verify you have chalice installed by running:

$ chalice --help
Usage: chalice [OPTIONS] COMMAND [ARGS]...
...

Credentials

Before you can deploy an application, be sure you have credentials configured. If you have previously configured your machine to run boto3 (the AWS SDK for Python) or the AWS CLI then you can skip this section.

If this is your first time configuring credentials for AWS you can follow these steps to quickly get started:

$ mkdir ~/.aws
$ cat >> ~/.aws/config
[default]
aws_access_key_id=YOUR_ACCESS_KEY_HERE
aws_secret_access_key=YOUR_SECRET_ACCESS_KEY
region=YOUR_REGION (such as us-west-2, us-west-1, etc)

If you want more information on all the supported methods for configuring credentials, see the boto3 docs.

Creating Your Project

The next thing we'll do is use the chalice command to create a new project:

$ chalice new-project helloworld

This will create a helloworld directory. Cd into this directory. You'll see several files have been created for you:

$ cd helloworld
$ ls -la
drwxr-xr-x   .chalice
-rw-r--r--   app.py
-rw-r--r--   requirements.txt

You can ignore the .chalice directory for now, the two main files we'll focus on is app.py and requirements.txt.

Let's take a look at the app.py file:

from chalice import Chalice

app = Chalice(app_name='helloworld')


@app.route('/')
def index():
    return {'hello': 'world'}

The new-project command created a sample app that defines a single view, /, that when called will return the JSON body {"hello": "world"}.

Deploying

Let's deploy this app. Make sure you're in the helloworld directory and run chalice deploy:

$ chalice deploy
Creating deployment package.
Creating IAM role: helloworld-dev
Creating lambda function: helloworld-dev
Creating Rest API
Resources deployed:
  - Lambda ARN: arn:aws:lambda:us-west-2:12345:function:helloworld-dev
  - Rest API URL: https://abcd.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/api/
{"hello": "world"}

Try making a change to the returned dictionary from the index() function. You can then redeploy your changes by running chalice deploy.

Next Steps

You've now created your first app using chalice. You can make modifications to your app.py file and rerun chalice deploy to redeploy your changes.

At this point, there are several next steps you can take.

  • Tutorials

    - Choose from among several guided tutorials that will give you step-by-step examples of various features of Chalice.

  • Topics - Deep dive into documentation on specific areas of Chalice. This contains more detailed documentation than the tutorials.
  • API Reference - Low level reference documentation on all the classes and methods that are part of the public API of Chalice.

If you're done experimenting with Chalice and you'd like to cleanup, you can use the chalice delete command, and Chalice will delete all the resources it created when running the chalice deploy command.

$ chalice delete
Deleting Rest API: abcd4kwyl4
Deleting function aws:arn:lambda:region:123456789:helloworld-dev
Deleting IAM Role helloworld-dev

Feedback

We'd also love to hear from you. Please create any Github issues for additional features you'd like to see over at https://github.com/aws/chalice/issues. You can also chat with us on gitter: https://gitter.im/awslabs/chalice

chalice's People

Contributors

aalvrz avatar adityamohta avatar artkay avatar dependabot-preview[bot] avatar dependabot[bot] avatar dmulter avatar gliptak avatar hamishfagg avatar hitrust avatar igorborgest avatar jamesls avatar jamielewis748 avatar jasonamyers avatar joech4n avatar jogusd avatar jordonphillips avatar jrbeilke avatar justinvzyl avatar kapilt avatar kmbotts avatar kyleknap avatar melevittfl avatar muriloviana avatar nplutt avatar ogrodnek avatar or-aidoc avatar shotguncrocodile avatar stealthycoin avatar subssn21 avatar xplorld avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

chalice's Issues

Support for access control with API Gateway

Is there any plan to support access control functionalities?
For example, only allowing federated identities to API GW, cognito integration, and so on.
If this is possible currently, I hope there are samples or example codes.

Support CloudFormation Templates

Most, if not all RESTful APIs require some sort of data source.

I'm not sure if this is out of scope for this project, hopefully not, but having the ability to deploy CloudFormation templates to buildout a DynamoDB table, or RDS instance etc would be beneficial.

It also makes cleanup, removing API Gateways, Lambda functions and roles much easier.

Add full support for stages

Right now, the stages feature needs more work to be feature complete. The proposed idea is:

  • chalice deploy prod - Will create a new API gateway stage if necessary
  • The lambda function code is zipped up and sent to lambda. A new function version is created
  • A lambda alias for the the stage name points to the new function version updated.

I also need to update the API gateway integration request to forward to the appropriate lambda function based on the stage name. I'll need to add a context variable with the stage name.

I'd also like to add an optimization to just update lambda aliases when you go from dev->prod where the lambda code has not changed. In that case we can just flip the alias.

Full url for other resources

Hi,
Is there a way to get the complete url for other resources in the api.
Ex: If there are two resources at (/resource1) and (/resource2) and resource2 needs to provide complete url for resource1. We use url_for in flask with _external=True. Is there a similar way to get the complete url?

Send post statement to DynamoDB

Hy,

I try to create an API gateway and I would like to store data into a DynamoDB table.
Set up chalice successfully and edited the app.py file.

from chalice import Chalice
import boto3

app = Chalice(app_name='appName')

@app.route('/', methods=['POST'])
def submit_data():

dynamodb = boto3.resource('dynamodb')
table = dynamodb.Table('TableName')

data = app.current_request.json_body

with table.batch_writer() as batch:
    for image in data['ImageList']:
        batch.put_item(
            Item={
                'StuffA': {
                    'Item_A': data['Item_A'],
                    'Item_B':    data['Item_B'],
                },'StuffB': {
                    'Item_C': data['Item_C'],
                    'Item_D':    data['Item_D'],
                },
            }
        )

return(Item)

Now if i try to submit a POST request (data which should be stored in DB is provided via JSON.

curl -H 'Content-Type: application/json' -v -d @test.json https://url_provided_by_chalice/dev/

I get the following error message any idea how to get it working? I did check AWS credentials as well.

  • Connected to ....... port 443 (#0)
  • ALPN, offering http/1.1
  • Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@strength
  • successfully set certificate verify locations:
  • CAfile: /home/.../anaconda3/envs/py27/ssl/cacert.pem
    CApath: none
  • TLSv1.2 (OUT), TLS header, Certificate Status (22):
  • TLSv1.2 (OUT), TLS handshake, Client hello (1):
  • TLSv1.2 (IN), TLS handshake, Server hello (2):
  • TLSv1.2 (IN), TLS handshake, Certificate (11):
  • TLSv1.2 (IN), TLS handshake, Server key exchange (12):
  • TLSv1.2 (IN), TLS handshake, Server finished (14):
  • TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
  • TLSv1.2 (OUT), TLS change cipher, Client hello (1):
  • TLSv1.2 (OUT), TLS handshake, Finished (20):
  • TLSv1.2 (IN), TLS change cipher, Client hello (1):
  • TLSv1.2 (IN), TLS handshake, Finished (20):
  • SSL connection using TLSv1.2 / ....SHA256
  • ALPN, server accepted to use http/1.1
  • Server certificate:
  • subject: C=US; ST=Washington; L=Seattle; O=Amazon.com, Inc.; CN=*.execute-api.ap-southeast-2.amazonaws.com
  • start date: Jun 3 00:00:00 2016 GMT
  • expire date: Jun 4 23:59:59 2017 GMT
  • subjectAltName: host "....." matched cert's "*.execute-api.ap-southeast-2.amazonaws.com"
  • issuer: C=US; O=Symantec Corporation; OU=Symantec Trust Network; CN=Symantec Class 3 Secure Server CA - G4
  • SSL certificate verify ok.

POST /dev/ HTTP/1.1
Host: dc8t02jg99.execute-api.ap-southeast-2.amazonaws.com
User-Agent: curl/7.49.0
Accept: /
Content-Type: application/json
Content-Length: 301

  • upload completely sent off: 301 out of 301 bytes
    < HTTP/1.1 500 Internal Server Error
    < Content-Type: application/json
    < Content-Length: 94
    < Connection: keep-alive
    < Date: Thu, 21 Jul 2016 04:38:32 GMT
    < x-amzn-RequestId:....
    < X-Cache: Error from cloudfront
    < Via: 1.1 .....cloudfront.net (CloudFront)
    < X-Amz-Cf-Id: YoeQ4H6La2w-vnfwUjQkhYYGrnagiHtz8yaW4sRk4n3XpX_9mwLHxA==
    <
  • Connection #0 to host .....execute-api.ap-southeast-2.amazonaws.com left intact
    {"Code": "ChaliceViewError","Message": "ChaliceViewError: An internal server error occurred."}

Any kind of help is appreciated!

Cheers

Support to upload custom binaries

Add support to upload binaries to the lambda function.
This may be a custom command or at least a detailed documentation on how to achieve that.

Our application uses external libraries and binaries not instalable through pip.

Confusing error message

I don't know if there is anything you can do about this since it is really API Gateway behavior but if you fumble-finger your URL and make the request to an unknown resource, you get:

HTTP/1.1 403 Forbidden
Connection: keep-alive
Content-Length: 42
Content-Type: application/json
Date: Mon, 27 Jun 2016 15:05:22 GMT
Via: 1.1 861b49a34b383ce3ac4ea8b7117b8953.cloudfront.net (CloudFront)
X-Amz-Cf-Id: wfIzVpXxb6UU68XwIgb4P-i4DmfgcbYYOfCMCu4UqJCSI68R3SdkxA==
X-Cache: Error from cloudfront
x-amzn-ErrorType: MissingAuthenticationTokenException
x-amzn-RequestId: 91fd08e2-3c78-11e6-8a68-23416dcaf8cc

{
    "message": "Missing Authentication Token"
}

which is kind of confusing.

Docs about how this compares to a bare python aws lambda implementation

After reading the docs I couldn't tell if it's possible to do the following or not, so maybe this is a matter of updating the docs to further clarify what is possible. So, before this framework came to existence I would deal with S3 updates by uploading a new aws lambda like this:

    aws lambda create-function --region someregion --function-name somename \
        --zip-file fileb://./somefile.zip --role somerole \
        --handler somename.handler --runtime python2.7 --profile default \
        --timeout 5 --memory-size 128

and then grant a permission related to S3:

    aws lambda add-permission --region someregion --function-name somename \
        --action "lambda:InvokeFunction" --principal s3.amazonaws.com \
        --source-arn somearn --source-account someacc --profile default \
        --statement-id someperm

somename.handler would contain something like:

def handler(event, context):
    for record in event['Records']:
        bucket = record['s3']['bucket']['name']
        key = record['s3']['object']['key']
    ...

Now, using chalice how would I implement that handler function that receives information about objects created on S3? Is it possible/trivial to do it here?

An error occurred (PolicyLengthExceededException) when calling the AddPermission operation

The Policy was not being correctly autogenerated as it did not include DynamoDB permissions, so I added lines manually to .chalice/policy.json, and build using "chalice deploy --no-autogen-policy".

This has been working just fine for the last day, however when deploying now, I'm getting the following error:

botocore.exceptions.ClientError: An error occurred (PolicyLengthExceededException) when calling the AddPermission operation: The final policy size (20789) is bigger than the limit (20480).

Nothing has changed in policy.json, and the deploy command was correctly working an hour ago.

I've tried slimming down .chalice/policy.json, but still getting the same error and the same size report (20789).

I've tried deleting the Role from AWS and redeploying. I then get my .chalice/policy.json shown to me and asked if I want to use it, and I select "y". The same error is presented.

CLI not compatible with Python 3+

Getting a syntax error when I try to run the CLI commands. The print statement in the CLI init.py file doesn't have parentheses:

    print event['timestamp'], event['logShortId'], event['message'].strip()
         ^
SyntaxError: invalid syntax

Expose raw body

I'm building a webhook for GitHub, and I want to validate the signature. The signature involves hashing of the raw body, which isn't available inside the Lambda function.

deploy fails using Federated Token authentication

I'm using temporary AWS tokens via GetFederationToken and as

You cannot use these credentials to call any IAM APIs.

running chalice deploy fails after a ListRoles call fails.

botocore.exceptions.ClientError: An error occurred (InvalidClientTokenId) when calling the ListRoles operation: The security token included in the request is invalid

Does chalice need to perform this ListRoles call?

Need a way of running the Lambda service locally

This would be great for testing and iterating locally, vs deploying and then validating.

(I couldn't find any references to this in the docs or source code, so apologies if this is already a feature)

chalice delete

I love the simplicity of the chalice CLI, but feel there is one more command to add to complete the feature set. That is a chalice delete (or named something similar) command.

I'm requesting this because chalice deploy automatically creates the Lambda function, the API Gateway routes and the IAM policy (and perhaps other things). It would be difficult for novice users and frustrating for advanced users to have to manually delete all those things themselves especially for failed experiments and hello word trials which the simplicity of the CLI encourages.

Policy role mngt

I run into a lost state of the IAM role for helloworld demo, the only way I managed to get out was to log into the console and delete the existing helloworld role in IAM.

(chalice-demo) ➜  helloworld git:(master) ✗ chalice deploy
Updating IAM policy.
Traceback (most recent call last):
  File "/Users/adhorn/.virtualenvs/chalice-demo/bin/chalice", line 9, in <module>
    load_entry_point('chalice==0.0.1', 'console_scripts', 'chalice')()
  File "/Users/adhorn/.virtualenvs/chalice-demo/lib/python2.7/site-packages/chalice-0.0.1-py2.7.egg/chalice/cli/__init__.py", line 161, in main
    return cli(obj={})
  File "/Users/adhorn/.virtualenvs/chalice-demo/lib/python2.7/site-packages/click-6.2-py2.7.egg/click/core.py", line 716, in __call__
    return self.main(*args, **kwargs)
  File "/Users/adhorn/.virtualenvs/chalice-demo/lib/python2.7/site-packages/click-6.2-py2.7.egg/click/core.py", line 696, in main
    rv = self.invoke(ctx)
  File "/Users/adhorn/.virtualenvs/chalice-demo/lib/python2.7/site-packages/click-6.2-py2.7.egg/click/core.py", line 1060, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/Users/adhorn/.virtualenvs/chalice-demo/lib/python2.7/site-packages/click-6.2-py2.7.egg/click/core.py", line 889, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Users/adhorn/.virtualenvs/chalice-demo/lib/python2.7/site-packages/click-6.2-py2.7.egg/click/core.py", line 534, in invoke
    return callback(*args, **kwargs)
  File "/Users/adhorn/.virtualenvs/chalice-demo/lib/python2.7/site-packages/click-6.2-py2.7.egg/click/decorators.py", line 17, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/Users/adhorn/.virtualenvs/chalice-demo/lib/python2.7/site-packages/chalice-0.0.1-py2.7.egg/chalice/cli/__init__.py", line 104, in deploy
    d.deploy(ctx.obj)
  File "/Users/adhorn/.virtualenvs/chalice-demo/lib/python2.7/site-packages/chalice-0.0.1-py2.7.egg/chalice/deployer.py", line 189, in deploy
    self._deploy_lambda(config)
  File "/Users/adhorn/.virtualenvs/chalice-demo/lib/python2.7/site-packages/chalice-0.0.1-py2.7.egg/chalice/deployer.py", line 205, in _deploy_lambda
    self._get_or_create_lambda_role_arn(config)
  File "/Users/adhorn/.virtualenvs/chalice-demo/lib/python2.7/site-packages/chalice-0.0.1-py2.7.egg/chalice/deployer.py", line 294, in _get_or_create_lambda_role_arn
    self._update_role_with_latest_policy(app_name, config)
  File "/Users/adhorn/.virtualenvs/chalice-demo/lib/python2.7/site-packages/chalice-0.0.1-py2.7.egg/chalice/deployer.py", line 310, in _update_role_with_latest_policy
    PolicyName=app_name)
  File "/Users/adhorn/.virtualenvs/chalice-demo/lib/python2.7/site-packages/botocore-1.4.30-py2.7.egg/botocore/client.py", line 278, in _api_call
    return self._make_api_call(operation_name, kwargs)
  File "/Users/adhorn/.virtualenvs/chalice-demo/lib/python2.7/site-packages/botocore-1.4.30-py2.7.egg/botocore/client.py", line 572, in _make_api_call
    raise ClientError(parsed_response, operation_name)
botocore.exceptions.ClientError: An error occurred (NoSuchEntity) when calling the DeleteRolePolicy operation: The role policy with name helloworld cannot be found.

running deploy on Windows raises "assert os.path.isfile(pip_exe)"

I'm following the tutorial instructions and getting the error below:

chalice deploy
Initial creation of lambda function.
Updating IAM policy.
Creating deployment package.
Traceback (most recent call last):
File "C:\Python27\Lib\runpy.py", line 162, in run_module_as_main
"main", fname, loader, pkg_name)
File "C:\Python27\Lib\runpy.py", line 72, in run_code
exec code in run_globals
File "C:\Users\rlloyd\venvs\chalice-demo\Scripts\chalice.exe__main
.py", line 9, in

...snipped...

_first_time_lambda_create
config['project_dir'])
File "c:\users\rlloyd\venvs\chalice-demo\lib\site-packages\chalice\deployer.py", line 633, in create_deployment_package
assert os.path.isfile(pip_exe)
AssertionError

List of resources created

I think the initial startup example is great. Seems like magic.

But I kind of wanted a command to have chalice show me all the resources that it had created on my behalf. Kind of an inventory. Just so I could get a better understanding of what was behind the magic.

Demo deploy fails with KeyError: 'Statement'

On a mac running 10.11.5 or an AWS Linux machine created today, deploying the demo from a fresh install of chalice generates an exception:

pip install virtualenv
virtualenv ~/.virtualenvs/chalice-demo
source ~/.virtualenvs/chalice-demo/bin/activate
pip install chalice
chalice new-project helloworld
cd helloworld
chalice deploy
->

Initial creation of lambda function.
Updating IAM policy.
Traceback (most recent call last):
  File "/home/ec2-user/.virtualenvs/chalice-demo/bin/chalice", line 9, in <module>
    load_entry_point('chalice==0.0.1', 'console_scripts', 'chalice')()
  File "/home/ec2-user/.virtualenvs/chalice-demo/local/lib/python2.7/site-packages/chalice/cli/__init__.py", line 203, in main
    return cli(obj={})
  File "/home/ec2-user/.virtualenvs/chalice-demo/local/lib/python2.7/site-packages/click/core.py", line 716, in __call__
    return self.main(*args, **kwargs)
  File "/home/ec2-user/.virtualenvs/chalice-demo/local/lib/python2.7/site-packages/click/core.py", line 696, in main
    rv = self.invoke(ctx)
  File "/home/ec2-user/.virtualenvs/chalice-demo/local/lib/python2.7/site-packages/click/core.py", line 1060, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/ec2-user/.virtualenvs/chalice-demo/local/lib/python2.7/site-packages/click/core.py", line 889, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/ec2-user/.virtualenvs/chalice-demo/local/lib/python2.7/site-packages/click/core.py", line 534, in invoke
    return callback(*args, **kwargs)
  File "/home/ec2-user/.virtualenvs/chalice-demo/local/lib/python2.7/site-packages/click/decorators.py", line 17, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/home/ec2-user/.virtualenvs/chalice-demo/local/lib/python2.7/site-packages/chalice/cli/__init__.py", line 123, in deploy
    d.deploy(ctx.obj)
  File "/home/ec2-user/.virtualenvs/chalice-demo/local/lib/python2.7/site-packages/chalice/deployer.py", line 203, in deploy
    self._deploy_lambda(config)
  File "/home/ec2-user/.virtualenvs/chalice-demo/local/lib/python2.7/site-packages/chalice/deployer.py", line 218, in _deploy_lambda
    function_arn = self._first_time_lambda_create(config)
  File "/home/ec2-user/.virtualenvs/chalice-demo/local/lib/python2.7/site-packages/chalice/deployer.py", line 259, in _first_time_lambda_create
    role_arn = self._get_or_create_lambda_role_arn(config)
  File "/home/ec2-user/.virtualenvs/chalice-demo/local/lib/python2.7/site-packages/chalice/deployer.py", line 304, in _get_or_create_lambda_role_arn
    self._update_role_with_latest_policy(app_name, config)
  File "/home/ec2-user/.virtualenvs/chalice-demo/local/lib/python2.7/site-packages/chalice/deployer.py", line 315, in _update_role_with_latest_policy
    diff = policy.diff_policies(previous, app_policy)
  File "/home/ec2-user/.virtualenvs/chalice-demo/local/lib/python2.7/site-packages/chalice/policy.py", line 38, in diff_policies
    old = _create_simple_format(old)
  File "/home/ec2-user/.virtualenvs/chalice-demo/local/lib/python2.7/site-packages/chalice/policy.py", line 53, in _create_simple_format
    for statement in policy['Statement']:
KeyError: 'Statement'

fails with error: failed to create process

I cannot seem to get it to work at all. all chalice commands fail with a single error message. My python version is 2.7.11, I am not running a venv. all other python libraries work fine for me.

failed to create process

Additional labels & project scope

Hi,

Could you please create additional labels like in-progress, out-of-scope and in-the-pipeline so that we could have better understanding about the scope of this project.

In my opinion #49 and #41 are the most important missing features of chalice. Is there a consensus whether this functionality is going to be implemented or is it out of scope?

Module import error

In order to separate out of one large app.py file, I want to split related code into helper modules, objects, etc and would expect a structure something like the below (just a rough fag-packet example):

  • app.js
    • shared
      • _ _ init _ _.py
      • objects.py
      • utils
        • _ _ init _ _.py
        • jsonutils.py

( _ init.py _ _ formatted to avoid markdown parsing)_

When importing a local module using the local python command from within a virtualenv, I can load the modules as you would expect to do, however when I run 'chalice deploy' or 'chalice deploy --no-autogen-policy', I receive an error:

ImportError: No module named blah>

I've tried various structures:

  1. objects.py file in the project folder
  2. objects.py file in a shared/ folder
  3. shared/ folder with an init.py file within
  4. shared/ folder with shared.py within

In code I've tried various combinations of import:

  1. import objects
  2. from . import objects
  3. import shared
  4. from shared import shared

None of these will work with deploy, which I'm guessing is due to some introspection logic as it works just as expected using local python command within the python2.7 virtualenv.

I've been on dialog with another developer who also confirms this as being a difficulty he encountered. For the immediate it looks like we'll need to write a kitchen sink app.py, but I'm hoping this is not intended behaviour.

chalice logs --num-entries doesn't work correctly

--num-entries doesn't work as expected. "START RequestId: ..." entries seem to ignore the flag for some reason and just show up.

$ chalice logs --num-entries 2
2016-06-20 15:59:36.860000 START RequestId: a86ac872-373a-11e6-bf61-d590e72a4e49 Version: $LATEST
2016-06-20 15:59:36.861000 END RequestId: a86ac872-373a-11e6-bf61-d590e72a4e49
2016-06-16 18:19:26.903000 START RequestId: 880485d1-3429-11e6-8bd1-5768f1a34d32 Version: $LATEST
2016-06-16 18:16:04.933000 START RequestId: 0fa1bc80-3429-11e6-89b5-e3700c93b565 Version: $LATEST
2016-06-16 18:12:37.280000 START RequestId: 93dcdc1d-3428-11e6-a3bb-47f354fceb6b Version: $LATEST
2016-06-16 17:56:00.222000 START RequestId: 41920974-3426-11e6-bc9c-db5f6f302eae Version: $LATEST
2016-06-16 17:54:18.662000 START RequestId: 050a2092-3426-11e6-9cec-cb1d421769ae Version: $LATEST
2016-06-16 17:47:08.940000 START RequestId: 04e799a7-3425-11e6-9fda-9f07bcaa2aa1 Version: $LATEST
2016-06-16 17:45:13.471000 START RequestId: c0177ac6-3424-11e6-9231-e513acaba488 Version: $LATEST
2016-06-16 17:11:56.440000 START RequestId: 19bf8b2b-3420-11e6-b5e1-4b20398ea566 Version: $LATEST
2016-06-16 17:08:31.982000 START RequestId: 9fe675fd-341f-11e6-b19d-d767ade7c1c9 Version: $LATEST
2016-06-16 17:08:01.404000 START RequestId: 8da4d8b5-341f-11e6-b436-fd8b48b1538a Version: $LATEST
2016-06-16 17:04:44.678000 START RequestId: 1789b563-341f-11e6-8f6e-6f465a8fb0d2 Version: $LATEST
2016-06-16 15:55:09.661000 START RequestId: 5f58ee84-3415-11e6-b1f3-1deb0eae2a01 Version: $LATEST

Add support for than app.py

The initial version of this framework only has support for an app.py file. I always envisioned being able to support more than this, while still trying to keep things small. What I had in mind:

  • You can either have a single app.py or, create an app/ directory.
  • The app/ directory must be a python package (__init__.py).
  • You still have to have an app object defined in __init__.py.
  • Everything in app/ will be included in the zip file distribution, including non python files.

This will allow you to split your app into multiple python modules as well as include data/config files with your app.

Keep in mind, the source code analyzer will likely need to be updated as well to handle more than just an app.py file.

Add support for non JSON payloads

Chalice is a really cool microframework! All the examples focus on returning JSON responses. Is it possible to serve HTML pages? Or to specify different response headers, e.g. 301 redirect and so on? Or is all of this out of scope and chalice is really just for writing REST JSON APIs?

Swagger Integration

Swagger has been hugely beneficial when developing RESTful APIs, being able to generate Swagger specs from a Chalice app would be a massive time saving.

Docstring could then be used to define Swagger specific options per endpoint to define Swagger specific config such as path variable types etc.

Explain the IAM policy magic

There is some pretty cool stuff going on with IAM policies but it's not explained anywhere. It's kind of cool that it just happens automatically but you definitely need a section on how it works.

Also, for the S3 example I noticed the policy just wildcards the resource. Is there anyway to figure out the actual bucket name being used and restrict the policy to just that resource?

Also, what are the limitations? What things aren't really detectable using this approach? For example, if my Lambda function has an SNS event source, I think it would be very difficult if not impossible to figure that out from the code.

Missing param in README docs

The README says:

    $ chalice new-project && cd new-project

But this results in:

(chalice) f45c89912ceb:chalice garnaat$ chalice new-project && cd new-project
Usage: chalice new-project [OPTIONS] PROJECT_NAME

Error: Missing argument "project_name".

The project_name is required.

Mention Zappa in the README

How does the Python Serverless Microframework for AWS compare to other similar frameworks?

Given that Zappa has already done this and more for many months, and that we've actually talked about this, it'd be nice to at least be mentioned in the similar frameworks section. We're a very similar framework that's more mature and more featureful. I do wish that you would have told us that you would be releasing an official AWS competitor to Zappa when we spoke so that we could have avoided so much duplication of effort.

Add the ability to specify a profile on the CLI

Some (most?) of us have access to multiple AWS accounts from the command line. It would be super-handy to be able to specify which profile to use with the --profile CLI argument like you can with awscli.

ChaliceViewError Should Print Real Error

tl;dr ChaliceViewError should print the underlying error message instead of hiding it (I think?)

[heavily edited]

By default, ChaliceViewError does not raise the underlying exception, it only prints "An internal server error occurred."
When app.debug = True, ChaliceViewError instead raises the underlying exception.

I think both of these features should be enabled at the same time. ChaliceViewError should print the real message (so that it is logged in CloudWatch) and then return a nicely-wrapped ChaliceViewError to the client. This way the developer can get errors logged without worrying about 'null' returns on bad requests.

I've had to do this to gain this functionality:
except Exception as e: print(e) raise e

And still every single error just gets raised as

Traceback (most recent call last): File "/var/task/chalice/__init__.py", line 148, in __call__ raise e
Which isn't helpful.

Chalice doesn't create resources beyond index

When using the sample from the docs e.g.:

from chalice import Chalice

app = Chalice(app_name='helloworld')

CITIES_TO_STATE = {
    'seattle': 'WA',
    'portland': 'OR',
}

@app.route('/')
def index():
    return {'hello': 'world'}

@app.route('/cities/{city}')
def state_of_city(name):
    return {'state': CITIES_TO_STATE[name]}

Chalice doesn't seem to create any resources beyond the index route. And attempting to call dev/cities/seattle returns a missing authentication error.

make IAM configurable

Running chalice deploy attempts to create a IAM role of the name of the application. Unfortunately, in my enterprise, not all AWS developers are allowed to create an IAM role for security best practices reasons. The entire IAM roles and policy thing should be configurable so that an IAM admin can create the required role/policy beforehand and grant use of it to developers.

missing dependency for boto3

(chalice) f45c89912ceb:foobar garnaat$ chalice logs
Traceback (most recent call last):
  File "/Users/garnaat/projects/chalice/bin/chalice", line 9, in <module>
    load_entry_point('chalice', 'console_scripts', 'chalice')()
  File "/Users/garnaat/projects/chalice/chalice/chalice/cli/__init__.py", line 161, in main
    return cli(obj={})
  File "/Users/garnaat/projects/chalice/lib/python2.7/site-packages/click-6.2-py2.7.egg/click/core.py", line 716, in __call__
    return self.main(*args, **kwargs)
  File "/Users/garnaat/projects/chalice/lib/python2.7/site-packages/click-6.2-py2.7.egg/click/core.py", line 696, in main
    rv = self.invoke(ctx)
  File "/Users/garnaat/projects/chalice/lib/python2.7/site-packages/click-6.2-py2.7.egg/click/core.py", line 1060, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/Users/garnaat/projects/chalice/lib/python2.7/site-packages/click-6.2-py2.7.egg/click/core.py", line 889, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Users/garnaat/projects/chalice/lib/python2.7/site-packages/click-6.2-py2.7.egg/click/core.py", line 534, in invoke
    return callback(*args, **kwargs)
  File "/Users/garnaat/projects/chalice/lib/python2.7/site-packages/click-6.2-py2.7.egg/click/decorators.py", line 17, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/Users/garnaat/projects/chalice/chalice/chalice/cli/__init__.py", line 134, in logs
    show_lambda_logs(ctx.obj, num_entries)
  File "/Users/garnaat/projects/chalice/chalice/chalice/cli/__init__.py", line 30, in show_lambda_logs
    import boto3
ImportError: No module named boto3

Add support for CloudWatch Event Source

I think Chalice is great framework!

I think following decorators are very useful:

@app.cron('0 12 * * ? *')
def index():
    return {"hello": "world"}

@app.rate('5 minutes')
def index():
    return {"hello": "world"}

"cron" and "rate" correspond to CloudWatch Events.
I want to use chalice available in a variety of situations.

Use exceptions to return error responses

I've not delved too deep into this yet, so I'm not sure how straight forward this would be to implement...

Having the ability to use exceptions to return an error response (and correct HTTP response code) would be extremely useful. A pseudo example:

Exception class:

class UnauthorizedException(ChaliceError):
    STATUS_CODE = 401

App logic:

if not authenticate(user):
    raise UnauthorizedException('You are not authenticated')

Response example (inc. correct response headers):

{"error": e.message}

Having quickly checked the source code, it looks like it should just be a cause of creating the exceptions and adding them to the ALL_ERRORS list.

Thoughts?

Support for Lambda versions and versioning within API Gateway

This is just an idea, so if you think this is not the place, please close this issue.

I've been thinking about a better versioning system for APIs on top of Lambda/API Gateway. It's nice you can create a stage variable and link that to an alias in Lambda. But Lambda also offers versioning, which is basically your API version... You would get something similar to https://zeit.co/now - where you deploy and get your URL back, but instead of just the stage, you could also get a version which lives forever and is hooked up to one of the aliases.

Although I have no clue yet on how to link that version to API gateway, it would be nice to think about it and see whether it is possible to get something like this done.

What do you think?

pip warning message could be confusing for new users

If you do a deploy on the basic hello world app described in the README, you get a warning from pip:

(chalice) f45c89912ceb:foobar garnaat$ chalice deploy
Initial creation of lambda function.
Creating role
Creating deployment package.
You must give at least one requirement to install (see "pip help install")
Lambda deploy done.
Initiating first time deployment...
Deploying to: dev
https://zjng833pbc.execute-api.us-east-1.amazonaws.com/dev/

It might be good to show this warning in the sample output in README just so new users don't see the message and worry that something has gone wrong.

"OSError: [Errno 2] No such file or directory" while running "chalice deploy"

It looks like it failed to deploy a lambda function after creating an IAM role successfully.

$ chalice deploy
Initial creation of lambda function.
Creating role
Creating deployment package.
Traceback (most recent call last):
File "/usr/local/bin/chalice", line 11, in
sys.exit(main())
File "/Library/Python/2.7/site-packages/chalice/cli/init.py", line 203, in main
return cli(obj={})
File "/Library/Python/2.7/site-packages/click/core.py", line 716, in call
return self.main(_args, *_kwargs)
File "/Library/Python/2.7/site-packages/click/core.py", line 696, in main
rv = self.invoke(ctx)
File "/Library/Python/2.7/site-packages/click/core.py", line 1060, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/Library/Python/2.7/site-packages/click/core.py", line 889, in invoke
return ctx.invoke(self.callback, *_ctx.params)
File "/Library/Python/2.7/site-packages/click/core.py", line 534, in invoke
return callback(_args, *_kwargs)
File "/Library/Python/2.7/site-packages/click/decorators.py", line 17, in new_func
return f(get_current_context(), *args, *_kwargs)
File "/Library/Python/2.7/site-packages/chalice/cli/init.py", line 123, in deploy
d.deploy(ctx.obj)
File "/Library/Python/2.7/site-packages/chalice/deployer.py", line 203, in deploy
self._deploy_lambda(config)
File "/Library/Python/2.7/site-packages/chalice/deployer.py", line 218, in _deploy_lambda
function_arn = self._first_time_lambda_create(config)
File "/Library/Python/2.7/site-packages/chalice/deployer.py", line 261, in _first_time_lambda_create
config['project_dir'])
File "/Library/Python/2.7/site-packages/chalice/deployer.py", line 630, in create_deployment_package
self._verify_has_virtualenv()
File "/Library/Python/2.7/site-packages/chalice/deployer.py", line 617, in _verify_has_virtualenv
subprocess.check_output(['virtualenv', '--version'])
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 566, in check_output
process = Popen(stdout=PIPE, _popenargs, *_kwargs)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 710, in init
errread, errwrite)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1335, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory

Export CHALICE_DEV_URL=<url-endpoint> ?

From the readme:

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 CLI displays when you deploy your API (it will look something like https://abcdefg.execute-api.us-west-2.amazonaws.com/dev/.

Why not let the chalice command-line export/set the URL as an environment variable? It should make scripting a lot easier (right now it would probably be possible to |tail -1 |read URL - but being able to check the exit-code of chalice, and then know that that one can go on with testing http ${CHALICE_DEV_URL} or equivalent might make things even easier?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.