def main():
    print(cwd)
    input_file_path = cwd + '/ruleapi.yaml'
    output_file_path = cwd + '/ruleapi_cfn.yaml'

    print(input_file_path)

    with open(input_file_path, 'r') as f:
        sam_template = yaml_parse(f)

    try:
        cloud_formation_template = transform(sam_template, {},
                                             ManagedPolicyLoader(iam_client))
        cloud_formation_template_prettified = json.dumps(
            cloud_formation_template, indent=2)

        with open(output_file_path, 'w') as f:
            f.write(cloud_formation_template_prettified)

        print('Wrote transformed CloudFormation template to: ' +
              output_file_path)
    except InvalidDocumentException as e:
        errorMessage = reduce(
            lambda message, error: message + ' ' + error.message, e.causes,
            e.message)
        print(errorMessage)
        errors = map(lambda cause: cause.message, e.causes)
        print(errors)
Exemplo n.º 2
0
def transform_template(input_file_path, output_file_path):
    with open(input_file_path, "r") as f:
        sam_template = yaml_parse(f)

    try:
        feature_toggle = FeatureToggle(
            FeatureToggleLocalConfigProvider(
                os.path.join(my_path, "..", "tests", "feature_toggle", "input",
                             "feature_toggle_config.json")))
        cloud_formation_template = transform(sam_template, {},
                                             ManagedPolicyLoader(iam_client),
                                             feature_toggle)
        cloud_formation_template_prettified = json.dumps(
            cloud_formation_template, indent=2)

        with open(output_file_path, "w") as f:
            f.write(cloud_formation_template_prettified)

        print("Wrote transformed CloudFormation template to: " +
              output_file_path)
    except InvalidDocumentException as e:
        errorMessage = reduce(
            lambda message, error: message + " " + error.message, e.causes,
            e.message)
        LOG.error(errorMessage)
        errors = map(lambda cause: cause.message, e.causes)
        LOG.error(errors)
def main():
    input_file_path, output_file_path = parse_arguments()

    with open(input_file_path) as f:
        sam_template = yaml_parse(f)

    iam = boto3.client('iam')
    cloudformation_template = transform(sam_template,
                                        {},
                                        ManagedPolicyLoader(iam))

    with open(output_file_path, 'w') as f:
        f.write(json.dumps(cloudformation_template, indent=2))

    print(f'Wrote transformed Cloudformation template to {output_file_path}')
Exemplo n.º 4
0
def main():
    input_file_path, output_file_path = get_input_output_file_paths()

    with open(input_file_path, 'r') as f:
        sam_template = yaml_parse(f)

    cloud_formation_template = transform(sam_template, {},
                                         ManagedPolicyLoader(iam_client))
    cloud_formation_template_prettified = json.dumps(cloud_formation_template,
                                                     indent=2)

    with open(output_file_path, 'w') as f:
        f.write(cloud_formation_template_prettified)

    print('Wrote transformed CloudFormation template to: ' + output_file_path)
def transform_template(input_file_path, output_file_path):
    with open(input_file_path, "r") as f:
        sam_template = yaml_parse(f)

    try:
        cloud_formation_template = transform(sam_template, {}, ManagedPolicyLoader(iam_client))
        cloud_formation_template_prettified = json.dumps(cloud_formation_template, indent=2)

        with open(output_file_path, "w") as f:
            f.write(cloud_formation_template_prettified)

        print ("Wrote transformed CloudFormation template to: " + output_file_path)
    except InvalidDocumentException as e:
        errorMessage = reduce(lambda message, error: message + " " + error.message, e.causes, e.message)
        LOG.error(errorMessage)
        errors = map(lambda cause: cause.message, e.causes)
        LOG.error(errors)
Exemplo n.º 6
0
def apply_sam_translate(template_string, logger):

  iam = boto3.client("iam")
  template = yaml.load(template_string, Loader=yaml.FullLoader)
  template = transform(template, {}, ManagedPolicyLoader(iam))
  return yaml.dump(template)
#!/usr/bin/env python

"""Script to convert AWS SAM templates to AWS CloudFormation templates.

Expects SAM template on stdin and prints out CloudFormation template on stdout.
"""

import sys

import boto3
import yaml
from cfn_tools import dump_yaml
from samtranslator.public.translator import ManagedPolicyLoader
from samtranslator.translator.transform import transform

input_fragment = yaml.load(sys.stdin.read())
iam_client = boto3.client('iam')
transformed = transform(input_fragment, {}, ManagedPolicyLoader(iam_client))
print(dump_yaml(transformed))