简体   繁体   English

AWS sam cli 打印 template.yaml 配置文件是否已解析所有变量

[英]Does AWS sam cli print template.yaml config file with all variables resolved

I have switched from serverless to sam cli.我已经从无服务器切换到 sam cli。 One useful function serverless had was serverless print which allowed you to print the output of your yaml file with all the local variables resolved.一个有用的 function 无服务器打印是无服务器打印,它允许您打印 yaml 文件的 output 并解析所有局部变量。 This was a useful tool for checking if your syntax is correct or if the variables are resolving as you expect.这是检查语法是否正确或变量是否按预期解析的有用工具。

Is that any way to do this with AWS sam cli?这有什么方法可以用 AWS sam cli 做到这一点吗?

eg例如

sam print

You can achieve this using Outputs section of SAM template.您可以使用 SAM 模板的Outputs部分来实现此目的。
You can check the AWS SAM template anatomy to understand better.您可以查看AWS SAM 模板剖析以更好地理解。

Outputs (optional)输出(可选)

The values that are returned whenever you view your stack's properties.每当您查看堆栈的属性时返回的值。 For example, you can declare an output for an S3 bucket name, and then call the aws cloudformation describe-stacks AWS Command Line Interface (AWS CLI) command to view the name.例如,您可以为 S3 存储桶名称声明 output,然后调用 aws cloudformation describe-stacks AWS 命令行界面 (AWS CLI) 命令查看名称。 This section corresponds directly with the Outputs section of AWS CloudFormation templates.此部分直接对应于 AWS CloudFormation 模板的输出部分。

You will need to make use of Intrinsic functions within your Outputs section to print out the final resolved value at runtime.您将需要使用Outputs部分中的内在函数来在运行时打印出最终解析的值。

Outputs:
  BackupLoadBalancerDNSName:
    Description: The DNSName of the backup load balancer
    Value: !GetAtt BackupLoadBalancer.DNSName
    Condition: CreateProdResources
  InstanceID:
    Description: The Instance ID
    Value: !Ref EC2Instance

If you just wish to validate if your SAM is correct or not you could use the following command:如果您只想验证您的SAM是否正确,您可以使用以下命令:

$ sam validate
Posting the answer here so that it may help others in future!在这里发布答案,以便将来可以帮助其他人!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在aws-sam template.yaml文件中添加插件 - how to add plugin in aws-sam template.yaml file aws-sam-cli Python requirements.txt 在自定义模板时从部署的 Lambda 中丢失。yaml - aws-sam-cli Python requirements.txt missing from deployed Lambda when custom template.yaml 根据来自 aws-sam template.yaml 文件的信息,使用 Java 在本地 AWS dynamoDB 中创建表 - Create tables in local AWS dynamoDB besed on information from aws-sam template.yaml file using Java 从 AWS 模板中的 json 文件加载配置数据。yaml 用于部署到 AWS Lambda - Loading config data from json file in AWS template.yaml for deploying to AWS Lambda 在 lambda 模板中添加值。yaml - Add values in lambda template.yaml 为 DynamoDB 模板使用 TableName 中的参数。yaml - Use parameter in TableName for DynamoDB template.yaml CodePipeline无法找到SAM模板yaml文件 - CodePipeline unable to locate SAM template yaml file 在 AWS SAM 模板中引用外部变量 - Refer outside variables in AWS SAM template 在template.yaml中创建多个API网关实例,运行'sam local start-api'时如何控制模仿哪个网关? - When creating multiple API Gateway instances in template.yaml, how do you control which Gateway is imitated when running 'sam local start-api'? AWS CLI无法读取配置文件 - AWS CLI not reading config file
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM