def translate(self, sam_template, parameter_values):
sam_parameter_values = SamParameterValues(parameter_values)<EOL>sam_parameter_values.add_default_parameter_values(sam_template)<EOL>sam_parameter_values.add_pseudo_parameter_values()<EOL>parameter_values = sam_parameter_values.parameter_values<EOL>sam_plugins = prepare_plugins(self.plugins, parameter_values)<EOL>self.sam_parser.parse(<EOL>sam_template=sam_template,<EOL>parameter_values=parameter_values,<EOL>sam_plugins=sam_plugins<EOL>)<EOL>template = copy.deepcopy(sam_template)<EOL>macro_resolver = ResourceTypeResolver(sam_resources)<EOL>intrinsics_resolver = IntrinsicsResolver(parameter_values)<EOL>deployment_preference_collection = DeploymentPreferenceCollection()<EOL>supported_resource_refs = SupportedResourceReferences()<EOL>document_errors = []<EOL>changed_logical_ids = {}<EOL>for logical_id, resource_dict in self._get_resources_to_iterate(sam_template, macro_resolver):<EOL><INDENT>try:<EOL><INDENT>macro = macro_resolver.resolve_resource_type(resource_dict).from_dict(logical_id, resource_dict, sam_plugins=sam_plugins)<EOL>kwargs = macro.resources_to_link(sam_template['<STR_LIT>'])<EOL>kwargs['<STR_LIT>'] = self.managed_policy_map<EOL>kwargs['<STR_LIT>'] = intrinsics_resolver<EOL>kwargs['<STR_LIT>'] = deployment_preference_collection<EOL>translated = macro.to_cloudformation(**kwargs)<EOL>supported_resource_refs = macro.get_resource_references(translated, supported_resource_refs)<EOL>if logical_id != macro.logical_id:<EOL><INDENT>changed_logical_ids[logical_id] = macro.logical_id<EOL><DEDENT>del template['<STR_LIT>'][logical_id]<EOL>for resource in translated:<EOL><INDENT>if verify_unique_logical_id(resource, sam_template['<STR_LIT>']):<EOL><INDENT>template['<STR_LIT>'].update(resource.to_dict())<EOL><DEDENT>else:<EOL><INDENT>document_errors.append(DuplicateLogicalIdException(<EOL>logical_id, resource.logical_id, resource.resource_type))<EOL><DEDENT><DEDENT><DEDENT>except (InvalidResourceException, InvalidEventException) as e:<EOL><INDENT>document_errors.append(e)<EOL><DEDENT><DEDENT>if deployment_preference_collection.any_enabled():<EOL><INDENT>template['<STR_LIT>'].update(deployment_preference_collection.codedeploy_application.to_dict())<EOL>if not deployment_preference_collection.can_skip_service_role():<EOL><INDENT>template['<STR_LIT>'].update(deployment_preference_collection.codedeploy_iam_role.to_dict())<EOL><DEDENT>for logical_id in deployment_preference_collection.enabled_logical_ids():<EOL><INDENT>template['<STR_LIT>'].update(deployment_preference_collection.deployment_group(logical_id).to_dict())<EOL><DEDENT><DEDENT>try:<EOL><INDENT>sam_plugins.act(LifeCycleEvents.after_transform_template, template)<EOL><DEDENT>except (InvalidDocumentException, InvalidResourceException) as e:<EOL><INDENT>document_errors.append(e)<EOL><DEDENT>if '<STR_LIT>' in template:<EOL><INDENT>del template['<STR_LIT>']<EOL><DEDENT>if len(document_errors) == <NUM_LIT:0>:<EOL><INDENT>template = intrinsics_resolver.resolve_sam_resource_id_refs(template, changed_logical_ids)<EOL>template = intrinsics_resolver.resolve_sam_resource_refs(template, supported_resource_refs)<EOL>return template<EOL><DEDENT>else:<EOL><INDENT>raise InvalidDocumentException(document_errors)<EOL><DEDENT>
Loads the SAM resources from the given SAM manifest, replaces them with their corresponding
        CloudFormation resources, and returns the resulting CloudFormation template.

        :param dict sam_template: the SAM manifest, as loaded by json.load() or yaml.load(), or as provided by \
                CloudFormation transforms.
        :param dict parameter_values: Map of template parameter names to their values. It is a required parameter that
                should at least be an empty map. By providing an empty map, the caller explicitly opts-into the idea
                that some functionality that relies on resolving parameter references might not work as expected
                (ex: auto-creating new Lambda Version when CodeUri contains reference to template parameter). This is
                why this parameter is required

        :returns: a copy of the template with SAM resources replaced with the corresponding CloudFormation, which may \
                be dumped into a valid CloudFormation JSON or YAML template