Repository navigation
feat(cli): add lightweight transformer cli - #459
Conversation
…tchSize from 200 to 10 (max)
| --output-file=<o> Location to store resulting CloudFormation template [default: cfn-template.json]. | ||
|
|
||
| """ | ||
| import os |
There was a problem hiding this comment.
Not sure if we're trying to follow PEP8 imports style guide, but if we are, the imports should be separated into 3 groups.
Imports should be grouped in the following order:
- Standard library imports.
- Related third party imports.
- Local application/library specific imports.
You should put a blank line between each group of imports.
| #!/usr/bin/env python2 | ||
|
|
||
| """Convert SAM templates to CloudFormation templates. | ||
| Known limitations: cannot transform CodeUri pointing at local directory. |
There was a problem hiding this comment.
Put a blank line between the summary and this line: https://www.python.org/dev/peps/pep-0257/#multi-line-docstrings
| cli_options = docopt(__doc__, sys.argv[1:]) | ||
| iam_client = boto3.client('iam') | ||
|
|
||
| if __name__ == '__main__': |
There was a problem hiding this comment.
Put the logic in a main() method and then call it from the conditional:
if __name__ == '__main__':
main()
| output_file_option = cli_options.get('--output-file') | ||
| input_file_path = os.path.join(cwd, input_file_option) | ||
| output_file_path = os.path.join(cwd, output_file_option) | ||
| samTemplate = yaml_parse(open(input_file_path, 'r')) |
There was a problem hiding this comment.
samTemplate -> sam_template
Also use blank lines to separate logical sections (arg parsing, transform template, write output)
| samTemplate = yaml_parse(open(input_file_path, 'r')) | ||
| cloud_formation_template = transform(samTemplate, {}, ManagedPolicyLoader(iam_client)) | ||
| cloud_formation_template_prettified = json.dumps(cloud_formation_template, indent=2) | ||
| print(cloud_formation_template_prettified) |
There was a problem hiding this comment.
Remove? Seems weird to print and write to an output file. If you really want to print it also, you should add a --quiet,-q option to suppress this behavior or conversely a --print option to enable it.
| cloud_formation_template = transform(samTemplate, {}, ManagedPolicyLoader(iam_client)) | ||
| cloud_formation_template_prettified = json.dumps(cloud_formation_template, indent=2) | ||
| print(cloud_formation_template_prettified) | ||
| cloud_formation_template_file = open(output_file_path, 'w') |
There was a problem hiding this comment.
Unless there's a good reason not to, always use the with statement to ensure files are closed after use:
with open(output_file_path, 'w') as f:
f.write(cloud_formation_template_prettified)
| .. _installation instructions: https://github.com/pyenv/pyenv#installation No newline at end of file | ||
| .. _installation instructions: https://github.com/pyenv/pyenv#installation | ||
|
|
||
| Profiling |
There was a problem hiding this comment.
Really appreciate you documenting this!
jlhood
left a comment
There was a problem hiding this comment.
Nice. This is a super useful tool! Mostly style/readability comments.
|
|
||
| import boto3 | ||
|
|
||
| from docopt import docopt |
There was a problem hiding this comment.
docopt should go in the same section as boto3, right?
| cwd = os.getcwd() | ||
|
|
||
|
|
||
| def getInputOutputFilePaths(): |
There was a problem hiding this comment.
getInputOutputFilePaths -> get_input_output_file_paths
| from samtranslator.translator.transform import transform | ||
| from samtranslator.yaml_helper import yaml_parse | ||
|
|
||
| cli_options = docopt(__doc__, sys.argv[1:]) |
There was a problem hiding this comment.
Why do you need to pass the additional param?
|
|
||
| def main(): | ||
| input_file_path, output_file_path = getInputOutputFilePaths() | ||
| sam_template = yaml_parse(open(input_file_path, 'r')) |
There was a problem hiding this comment.
Does yaml_parse close this file handle? Hopefully it doesn't and you should:
with open(input_file_path, 'r') as f:
sam_template = yaml_parse(f)
jlhood
left a comment
There was a problem hiding this comment.
Just a few more minor things, then it should be good to go.
jlhood
left a comment
There was a problem hiding this comment.
Looks great! Thanks for iterating!
* doc: update DESIGN.md to include an Overview and entry point for SAM (#370) * Update DESIGN.md to include an Overview and entry point for SAM * Updated wording in DESIGN.md based on PR feedback * docs(example): improve microservice-http-endpoint-python3 example (#415) * Remove unnecessary index.js" * Moved common config to template Globals and uncomment debug log. * Add sample payload and commands for testing. * Rename test script as a script. * Exit from script after command. * Simplify use case for easier startup. - Move table creation into template. - Eliminates need to provide table name in every REST call. - Fix GET with no params. - Split test.sh script from output log. * Address requested changes. * doc(example): update api_backend example to use ES6 arrow function immediate return (#446) Since this code is using ES6 we can use the short version of returning a param * feat(event-source): add SQS as Lambda event source (#451) * feat(cli): add lightweight transformer cli (#459) * bug: fix ANY method ARN generation using wildcard (#449) * fix(event-source): fix SQS Queue schema to allow intrinsic functions (#465) * fix: log a warning on invalid schema validation (#466)
* doc: update DESIGN.md to include an Overview and entry point for SAM (#370) * Update DESIGN.md to include an Overview and entry point for SAM * Updated wording in DESIGN.md based on PR feedback * docs(example): improve microservice-http-endpoint-python3 example (#415) * Remove unnecessary index.js" * Moved common config to template Globals and uncomment debug log. * Add sample payload and commands for testing. * Rename test script as a script. * Exit from script after command. * Simplify use case for easier startup. - Move table creation into template. - Eliminates need to provide table name in every REST call. - Fix GET with no params. - Split test.sh script from output log. * Address requested changes. * doc(example): update api_backend example to use ES6 arrow function immediate return (#446) Since this code is using ES6 we can use the short version of returning a param * feat(event-source): add SQS as Lambda event source (#451) * feat(cli): add lightweight transformer cli (#459) * bug: fix ANY method ARN generation using wildcard (#449) * fix(event-source): fix SQS Queue schema to allow intrinsic functions (#465) * fix: log a warning on invalid schema validation (#466)
Issue #, if available:
Description of changes:
bin/sam-translate.py --input-file=sam-template.yamloutputs acfn-template.jsonfile (can specify output with--output-file=By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.