无法使用权杖预钩子设置环境变量



我正在尝试使用 sceptre !cmd 钩子(在创建/更新之前(设置一个环境变量,然后可以通过在同一配置文件中使用 !environment_variable 解析器sceptre_user_data来解决。

该命令在从 shell 执行时运行良好,但由于某种原因,!cmd 钩子在运行时不执行分配

不知道,如果我在这里错过了什么

hooks:
  before_create:
    - !cmd "export OBJECT_VERSION=$(aws s3api put-object --body file --bucket bucket-name --key path --query 'VersionId')"
sceptre_user_data:
  ObjectVersion: !environment_variable OBJECT_VERSION
不幸的是,

您目前需要一个自定义解析器

sceptre_plugins_cmd_extras.py

import os
import subprocess
from sceptre.resolvers import Resolver

class CmdResolver(Resolver):
    """
    Resolver for running shell commands and returning the value
    :param argument: Name of the environment variable to return.
    :type argument: str
    """
    def resolve(self):
        """
        Runs a command and returns the output as a string
        :returns: Value of the environment variable.
        :rtype: str
        """
        return subprocess.check_output(self.argument, shell=True)

setup.py

from setuptools import setup
setup(
    name='sceptre-plugins-cmd-extras',
    description="Extra Sceptre Plguins (Hook & Resolver) for subprocess",
    keywords="sceptre,cloudformation",
    version='0.0.1',
    author="Cloudreach",
    author_email="juan.canham@cloudreach.com",
    license='Apache2',
    url="https://github.com/cloudreach/sceptre",
    entry_points={
        'sceptre.resolvers': [
            'cmd = sceptre_plugins_cmd_extras:CmdResolver',
        ],
    },
    py_modules=['sceptre_plugins_cmd_extras'],
    install_requires=["sceptre"],
    classifiers=[
        "Development Status :: 3 - Alpha",
        "Intended Audience :: Developers",
        "Intended Audience :: System Administrators"
        "Natural Language :: English",
        "Environment :: Plugins",
        "Programming Language :: Python :: 2.6",
        "Programming Language :: Python :: 2.7",
        "Programming Language :: Python :: 3.5",
        "Programming Language :: Python :: 3.6",
        "Programming Language :: Python :: 3.7"
    ]
)

但是你需要使你的命令是幂等的(类似(

sceptre_user_data:
  ObjectVersion: !cmd aws s3api get-object --bucket bucket-name --key path --query 'VersionId' || aws s3api put-object --body file --bucket bucket-name --key path --query 'VersionId'

最新更新