无服务器堆栈输出插件
A 类 无服务器 插件将您的 AWS CloudFormation Stack 输出存储于 JSON/YAML/TOML 文件, 或将输出传递给 JavaScript 函数进行进一步处理 .
使用量
安装
$ > yarn add serverless-stack-output
$ > npm install serverless-stack-output
配置
plugins:
- serverless-stack-output
custom:
output:
handler: scripts/output.handler # Same syntax as you already know
file: .build/stack.toml # toml, yaml, yml, and json format is available
处理器
根据上面的配置, 插件将搜索一个文件 scripts/output.js 内容如下:
function handler (data, serverless, options) {
console.log('Received Stack Output', data)
}
module.exports = { handler }
文件格式
用一个名字命名你的档案 .json, (中文(简体) ), .toml, (中文(简体) ), .yaml,或 .yml 扩展名,插件将注意格式化您的输出。 请确定要保存文件的位置是否存在 !
许可证
可以随意使用代码,它使用 麻省理工学院许可证。 。 。 .
捐款
欢迎你们为这个项目出力
为了保证你有一个愉快的经验, 请阅读 行为守则它概述了核心价值观,相信并将使共同工作成为更幸福的经历.
示例
插件在无服务器功能的情况下,以及在使用自定义 CloudFormation 资源时,效果很好. 以下示例配置将部署 AWS Lambda 函数, API Gateway, SQS Quue, 有 AccessKey 和 SecretKey 的 IAM 用户, 以及一个静态值 :
无服务器. yml
service: sls-stack-output-example
plugins:
- serverless-stack-output
package:
exclude:
- node_modules/**
custom:
output:
handler: scripts/output.handler
file: .build/stack.toml
provider:
name: aws
runtime: nodejs6.10
functions:
example:
handler: functions/example.handle
events:
- http:
path: example
method: get
cors: true
resources:
Resources:
ExampleQueue:
Type: AWS::SQS::Queue
Properties:
QueueName: example-queue
ExampleUser:
Type: "AWS::IAM::User"
Properties:
UserName: example-user
Policies:
- PolicyName: ExampleUserSQSPolicy
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: "Allow"
Action:
- sqs:SendMessage
Resource:
- {"Fn::Join": [":", ["arn:aws:sqs:*", {"Ref": "AWS::AccountId"}, "example-queue"]]}
ExampleUserKey:
Type: AWS::IAM::AccessKey
Properties:
UserName:
Ref: ExampleUser
Outputs:
ExampleUserKey:
Value:
Ref: ExampleUserKey
ExampleUserSecret:
Value: {"Fn::GetAtt": ["ExampleUserKey", "SecretAccessKey"]}
ExampleStaticValue:
Value: example-static-value
堆栈输出
移动
ExampleUserSecret = "YourUserSecretKey"
ExampleUserKey = "YourUserAccessKey"
ExampleLambdaFunctionQualifiedArn = "arn:aws:lambda:us-east-1:AccountID:function:sls-stack-output-example-dev-example:9"
ExampleStaticValue = "example-static-value"
ServiceEndpoint = "https://APIGatewayID.execute-api.us-east-1.amazonaws.com/dev"
ServerlessDeploymentBucketName = "sls-stack-output-example-serverlessdeploymentbuck-BucketID"
也门
ExampleUserSecret: YourUserSecretKey
ExampleUserKey: YourUserAccessKey
ExampleLambdaFunctionQualifiedArn: 'arn:aws:lambda:us-east-1:AccountID:function:sls-stack-output-example-dev-example:9'
ExampleStaticValue: example-static-value
ServiceEndpoint: 'https://APIGatewayID.execute-api.us-east-1.amazonaws.com/dev'
ServerlessDeploymentBucketName: sls-stack-output-example-serverlessdeploymentbuck-BucketID
贾森
{
"ExampleUserSecret": "YourUserSecretKey",
"ExampleUserKey": "YourUserAccessKey",
"ExampleLambdaFunctionQualifiedArn": "arn:aws:lambda:us-east-1:AccountID:function:sls-stack-output-example-dev-example:9",
"ExampleStaticValue": "example-static-value",
"ServiceEndpoint": "https://APIGatewayID.execute-api.us-east-1.amazonaws.com/dev",
"ServerlessDeploymentBucketName": "sls-stack-output-example-serverlessdeploymentbuck-BucketID"
}