【问题标题】:automate uploading of glue script自动上传胶水脚本
【发布时间】:2020-01-16 13:34:49
【问题描述】:

我们目前正在使用云形成来创建粘合作业(通过 codebuild 和 codepipeline)。我们坚持的一件事是如何自动化进入胶水作业的代码。

我们当前的相关部分 cloudformation 模板如下所示:

MyJob:
    Type: AWS::Glue::Job
    Properties:
      Command:
        Name: glueetl
        ScriptLocation: "s3://aws-glue-scripts//your-script-file.py"
      DefaultArguments:
        "--job-bookmark-option": "job-bookmark-enable"
      ExecutionProperty:
        MaxConcurrentRuns: 2
      MaxRetries: 0
      Name: cf-job1
      Role: !Ref MyJobRole

问题是“ScriptLocation”。看起来它必须是 S3 位置。我们如何自动上传这个。代码在我们的 Git 存储库中的 .py 文件中,我假设已像代码构建过程一样上传到工件存储库,但是如何访问它?

想听听其他人是怎么做的。谢谢!

编辑:我找到了类似的堆栈溢出帖子:AWS Glue automatic job creation,但答案确实没有给出解决方案或理解提出的问题。

【问题讨论】:

    标签: amazon-cloudformation aws-glue


    【解决方案1】:

    我编写了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 个部分:

    1. xsh:它是一个 bash 库框架。
    2. 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 等依赖项抽象为配置和处理程序的单个接口。 这将使向部署程序添加新的依赖处理程序变得更加容易。

    【讨论】:

      猜你喜欢
      • 2018-10-30
      • 2019-06-19
      • 1970-01-01
      • 2022-01-23
      • 2016-06-23
      • 2013-03-18
      • 2021-07-07
      • 1970-01-01
      • 2023-04-11
      相关资源
      最近更新 更多