Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Сustomizing resources generated by Chalice (and cdk-chalice respectively) #15

natCyberark opened this issue Apr 20, 2020 · 4 comments
enhancement New feature or request


Copy link

natCyberark commented Apr 20, 2020

Hi !

We have a problem to enable API-Gateway logging in our cdk cloudformation template and providing it with role, that allows writing to cloudwatch.

We use chalice framework for building our lambda functions and because of it, we don't have direct access to API-Gateway configuration.

We added below code to cdk_chalice lib def _update_sam_template(self) :

functions = filter(
    lambda resource: resource['Type'] == 'AWS::Serverless::Api',
for function in functions:
    function['Properties']['MethodSettings'] = [{
        "DataTraceEnabled": True,
        "HttpMethod": "*",
        "LoggingLevel": "INFO",
        "ResourcePath": "/* "

and it seemed to work.

Alex, as we agreed, I'm opening the issue, because you wanted to : "tackle it and see whether customizing resources generated by Chalice (and cdk-chalice respectively) can be made easier."

Thank you !

@alexpulver alexpulver self-assigned this Apr 28, 2020
@alexpulver alexpulver added the enhancement New feature or request label Apr 28, 2020
Copy link

alexpulver commented May 13, 2020

Thanks for submitting the issue! I'll start by zooming out a bit and recap cdk-chalice intent. The package is meant to automate the following approach to AWS CDK and AWS Chalice interoperability:

  1. Create Chalice application (chalice new-project) with default "dev" stage in .chalice/config.json. CDK application could perform this Chalice application scaffolding - create new project or skip this step if project already exists in the target directory (this is chalice new-project behavior). I preferred to keep this step manual to hopefully make adoption easier for developers who already have existing Chalice projects

  2. Create CDK application (cdk init)

  3. Use cdk_chalice.Chalice class to generate stage per CDK stack in .chalice/config.json and run chalice package. This is the main purpose of cdk-chalice - to allow passing CDK tokens for resources such as DynamoDB table to SAM template generated by chalice package (see example here), and also to automate the packaging process itself.

Hence if AWS Chalice doesn't support accepting certain options through its configuration mechanism, there are two options I can think of - open an issue for AWS Chalice or customize the resources after they have been imported into the CDK stack by cdk-chalice. To make the latter easier, there is a tracking issue in AWS CDK for migrating CloudFormation templates to the CDK.

Does it make sense?

Copy link

alexpulver commented May 13, 2020

To clarify, once migrating CloudFormation templates to the CDK is released, I will look for integrating it into cdk-chalice itself, such that you will get CDK objects to work with for SAM template generated by chalice package.

Copy link

@natCyberark I released cdk-chalice 0.8.0 that includes this capability, based on AWS CDK cloudformation_include module (it just reached developer preview status). The cdk-chalice API documentation includes more information and usage example. Would be glad to get your feedback!

Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
enhancement New feature or request
None yet

No branches or pull requests

2 participants