通过 CDK 代码更新 Glue 触发器

0

【以下的问题经过翻译处理】 您好,

我正在尝试使用CDK customResource 来更新一个 Glue 触发器的EventBatchingCondition(因为它不是CloudFormation原生支持的)。

这是我的代码:

    new AwsCustomResource(this, "updateEventBatching", {
      policy: AwsCustomResourcePolicy.fromSdkCalls({
        resources: AwsCustomResourcePolicy.ANY_RESOURCE,
      }),
      onCreate: {
        service: "Glue",
        action: "updateTrigger",
        parameters: {
          Name: myGlueTrigger.name, //The name of the trigger to update.
          TriggerUpdate: {
            EventBatchingCondition: {
              BatchSize: "20",
              BatchWindow: "900",
            },
          },
        },

        physicalResourceId: PhysicalResourceId.of(
          "updateEventBatching_id"
        ),
      },
      onUpdate: {
        service: "Glue",
        action: "updateTrigger ",
        parameters: {
          Name: myGlueTrigger.name, //The name of the trigger to update.
          TriggerUpdate: {
            EventBatchingCondition: {
              BatchSize: "20" ,
              BatchWindow: "300",
            },
          },
        },
        physicalResourceId: PhysicalResourceId.of("updateEventBatching_id"),
      },
    });

我遵循了这篇文章来获取服务名称、操作和参数: https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/Glue.html#updateTrigger-property

当我尝试部署时,遇到了这个错误:

不确定问题是操作服务不正确,还是其他原因。

此外,我不确定在这种情况下应该在“physicalResourceId”参数中填什么,我只是放了一个静态字符串。

node_modules\aws-cdk-lib\aws-iam\lib\policy-statement.js:1
"use strict";var _a;Object.defineProperty(exports,"__esModule",{value:!0}),exports.Effect=exports.PolicyStatement=void 0;const jsiiDeprecationWarnings=require("../../.warnings.jsii.js"),JSII_RTTI_SYMBOL_1=Symbol.for("jsii.rtti"),cdk=require("../../core"),group_1=require("./group"),principals_1=require("./principals"),postprocess_policy_document_1=require("./private/postprocess-policy-document"),util_1=require("./util"),ensureArrayOrUndefined=field=>{if(field!==void 0){if(typeof field!="string"&&!Array.isArray(field))throw new Error("Fields must be either a string or an array of strings");if(Array.isArray(field)&&!!field.find(f=>typeof f!="string"))throw new Error("Fields must be either a string or an array of strings");return Array.isArray(field)?field:[field]}};class PolicyStatement{constructor(props={}){this.action=new Array,this.notAction=new Array,this.principal={},this.notPrincipal={},this.resource=new Array,this.notResource=new Array,this.condition={},this._principals=new Array;try{jsiiDeprecationWarnings.aws_cdk_lib_aws_iam_PolicyStatementProps(props)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.constructor),error}for(const action of[...props.actions||[],...props.notActions||[]])if(!/^(\*|[a-zA-Z0-9-]+:[a-zA-Z0-9*]+)$/.test(action)&&!cdk.Token.isUnresolved(action))throw new Error(`Action '${action}' is invalid. An action string consists of a service namespace, a colon, and the name of an action. Action names can include wildcards.`);this.sid=props.sid,this.effect=props.effect||Effect.ALLOW,this.addActions(...props.actions||[]),this.addNotActions(...props.notActions||[]),this.addPrincipals(...props.principals||[]),this.addNotPrincipals(...props.notPrincipals||[]),this.addResources(...props.resources||[]),this.addNotResources(...props.notResources||[]),props.conditions!==void 0&&this.addConditions(props.conditions)}static fromJson(obj){const ret=new PolicyStatement({sid:obj.Sid,actions:ensureArrayOrUndefined(obj.Action),resources:ensureArrayOrUndefined(obj.Resource),conditions:obj.Condition,effect:obj.Effect,notActions:ensureArrayOrUndefined(obj.NotAction),notResources:ensureArrayOrUndefined(obj.NotResource),principals:obj.Principal?[new JsonPrincipal(obj.Principal)]:void 0,notPrincipals:obj.NotPrincipal?[new JsonPrincipal(obj.NotPrincipal)]:void 0}),errors=ret.validateForAnyPolicy();if(errors.length>0)throw new Error("Incorrect Policy Statement: "+errors.join(`





                                                                                                                                                                                    ^
Error: Action 'glue:UpdateTrigger ' is invalid. An action string consists of a service namespace, a colon, and the name of an action. Action names can include wildcards.
    at new PolicyStatement (C:\xxxx\node_modules\aws-cdk-lib\aws-iam\lib\policy-statement.js:1:1371)
    at new AwsCustomResource (C:\xxxx\node_modules\aws-cdk-lib\custom-resources\lib\aws-custom-resource\aws-custom-resource.js:1:4109)
    at new CdkGlueEdwLoadStack (C:\xxxxxx\lib\cdk-glue-edw-load-stack.ts:634:5)
    at Object.<anonymous> (C:\xxxxx\bin\index.ts:115:1)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)
    at Module.m._compile (C:\xxxxx\node_modules\ts-node\src\index.ts:1056:23)
    at Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
    at Object.require.extensions.<computed> [as .ts] (C:\xxxxx\node_modules\ts-node\src\index.ts:1059:12)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
profile picture
专家
已提问 5 个月前24 查看次数
1 回答
0

【以下的回答经过翻译处理】 我最终添加了一个 IAM 策略:

使用 AwsCustomResourcePolicy.fromStatements 代替 AwsCustomResourcePolicy.fromSdkCalls

new AwsCustomResource(this, "resourceId", {
  policy: AwsCustomResourcePolicy.fromStatements([
    new iam.PolicyStatement({
      effect: iam.Effect.ALLOW,
      actions: ["glue:UpdateTrigger"],
      resources: [
        `myGlueTrigger_ARN`,
      ], 
    }),
  ]),
  onCreate: {
       ......
       ......

但如果有人知道以下的方法为什么不起作用,请分享一下:

policy: AwsCustomResourcePolicy.fromSdkCalls({
    resources: AwsCustomResourcePolicy.ANY_RESOURCE,
  }
profile picture
专家
已回答 5 个月前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则