我目前正试图使用AWS CDK(Python(向粘合爬网程序添加一条策略语句,但在尝试使用get_att((方法从爬网程序中检索爬网程序的ARN时遇到了问题(此处为文档(。我已经提供了用于创建爬网程序的代码,然后希望使用策略文档将该语句添加到资源中。如果有人认为这会有所帮助,我很乐意提供更多信息。提前感谢您抽出时间!
from aws_cdk import (
aws_glue,
aws_iam
)
def new_glueCrawler(stack):
glue_job_role = aws_iam.Role(
stack,
'roleName',
role_name='roleName',
assumed_by=aws_iam.ServicePrincipal('glue.amazonaws.com'),
managed_policies=[aws_iam.ManagedPolicy.from_aws_managed_policy_name('service-role/AWSGlueServiceRole')])
def prepend(list, str):
str += '{0}'
list = [{"path": str.format(i)} for i in list]
return(list)
s3TargetList = prepend('pathList', 'bucketName')
glueCrawler = aws_glue.CfnCrawler(stack, 'crawlerName',
name='crawlerName',
role=glue_job_role.role_arn,
targets={"s3Targets": s3TargetList},
crawler_security_configuration='securityName',
database_name='dbName',
schedule=aws_glue.CfnCrawler.ScheduleProperty(schedule_expression='cron(5 2 * * ? *)'),
schema_change_policy=aws_glue.CfnCrawler.SchemaChangePolicyProperty(delete_behavior='DELETE_FROM_DATABASE',
update_behavior='UPDATE_IN_DATABASE'))
return glueCrawler
adminPolicyDoc = aws_iam.PolicyDocument()
adminPolicyDoc.add_statements([aws_iam.PolicyStatement(actions=['glue:StartCrawler'],
effect=aws_iam.Effect.ALLOW,
resources=[glueCrawler.get_att('arn')]
)
]
)
不幸的是,使用CfCrawler,这个过程不如使用CDK框架中的其他对象那么好。例如,如果您想获得lambdaObject的arn,您可以简单地调用lambdaObject.function_arn
。克劳勒的似乎没那么容易。如有任何见解,我们将不胜感激!
因此,我能够使用以下代码片段获取arn,其中爬网程序是我试图获取arn的对象:core.Stack.of(stack).format_arn(service='glue',resource='crawler',resource_name=crawler.name)
看起来你就快到了,我相信"秘密字符串";要获得arn属性,请执行以下操作:"resource.arn";,所以改一下这行:
resources=[glueCrawler.get_att('arn')]
至:
resources=[glueCrawler.get_att('resource.arn')]