我编写了a tool 来处理堆栈依赖项的上传,包括 CloudFormation 嵌套模板和非内联 Lambda 函数。
目前尚未处理 AWS Glue,因为我还没有在任何项目中尝试过它。但它应该很容易扩展以支持 Glue。
依赖项是在单独的配置文件中定义的,工具中的一段代码负责配置。这是示例配置:
嵌套 CloudFormation 模板:
# DEPENDS=( <ParameterName>=<NestedTemplate> )
#
# Required: Yes if has nested template, otherwise No
# Default: None
# Syntax:
# <ParameterName>: The name of template parameter that is referred at the
# value of nested template property `TemplateURL`.
# <NestedTemplate>: A local path or a S3 URL starting with `s3://` or
# `https://` pointing to the nested template.
# The nested templates at local is going to be uploaded
# to S3 Bucket automatically during the deployment.
# Description:
# Double quote the pairs which contain whitespaces or special characters.
# Use `#` to comment out.
# ---
# Example:
# DEPENDS=(
# NestedTemplateFooURL=/path/to/nested/foo/stack.json
# NestedTemplateBarURL=/path/to/nested/bar/stack.json
# )
Lambda 函数:
# LAMBDA=( <S3BucketParameterName>:<S3KeyParameterName>=<LambdaFunction> )
#
# Required: Yes if has None-inline Lambda Function, otherwise No
# Default: None
# Syntax:
# <S3BucketParameterName>: The name of template parameter that is referred
# at the value of Lambda property `Code.S3Bucket`.
# <S3KeyParameterName>: The name of template parameter that is referred
# at the value of Lambda property `Code.S3Key`.
# <LambdaFunction>: A local path or a S3 URL starting with `s3://` pointing
# to the Lambda Function.
# The Lambda Functions at local is going to be zipped and
# uploaded to S3 Bucket automatically during the deployment.
# Description:
# Double quote the pairs which contain whitespaces or special characters.
# Use `#` to comment out.
# ---
# Example:
# DEPENDS=(
# S3BucketForLambdaFoo:S3KeyForLambdaFoo=/path/to/LambdaFoo.py
# S3BucketForLambdaBar:S3KeyForLambdaBar=s3://mybucket/LambdaBar.py
# )
这些工具是用 bash 编写的,包含 2 个部分:
-
xsh:它是一个 bash 库框架。
-
xsh-lib/aws: 是一个 xsh 的库。
您可能需要扩展的代码位于xsh-lib/aws/functions/cfn/deploy.sh。
示例部署命令如下所示:
$ xsh aws/cfn/deploy -C /path/to/your/template-and-config-dir -t stack.json -c sample.conf
我正在考虑将 CloudFormation 模板、Lambda 函数和 Glue 等依赖项抽象为配置和处理程序的单个接口。
这将使向部署程序添加新的依赖处理程序变得更加容易。