实现cdk自定义资源的结构
aws-cdk.custom-resources的Python项目详细描述
CDK自定义资源
This is a developer preview (public beta) module. Releases might lack important features and might have future breaking changes.
This API is still under active development and subject to non-backward compatible changes or removal in any future version. Use of the API is not recommended in production environments. Experimental APIs are not subject to the Semantic Versioning model.
这个模块是AWS Cloud Development Kit项目的一部分。
AWS自定义资源
有时候一个api调用就可以填补cloudformation覆盖率的空白。在
在这种情况下,您可以使用AwsCustomResource
构造。这个构造创建
一个自定义资源,可以对其进行自定义以对
CREATE
、UPDATE
和DELETE
事件。此外,api返回的数据
可以提取调用并在其他构造/资源中使用(创建
在hood下使用Fn::GetAtt
的cloudformation依赖项)。
自定义资源的物理ID可以指定或从数据派生 由API调用返回。
AwsCustomResource
将aws sdk用于javascript。服务、行动和
参数可以在API documentation中找到。
必须使用点表示法指定数据路径,例如,要获取字符串值
对于由dynamodb.query
返回的第一个项的Title
属性,它应该
是Items.0.Title.S
。
示例
使用ses验证域:
constverifyDomainIdentity=newAwsCustomResource(this,'VerifyDomainIdentity',{onCreate:{service:'SES',action:'verifyDomainIdentity',parameters:{Domain:'example.com'},physicalResourceIdPath:'VerificationToken'// Use the token returned by the call as physical id}});newroute53.TxtRecord(zone,'SESVerificationRecord',{recordName:`_amazonses.example.com`,recordValue: verifyDomainIdentity.getData('VerificationToken')});
获取最新版本的安全SSM参数:
constgetParameter=newAwsCustomResource(this,'GetParameter',{onUpdate:{// will also be called for a CREATE eventservice:'SSM',action:'getParameter',parameters:{Name:'my-parameter',WithDecryption: true},physicalResourceId: Date.now().toString()// Update physical id to always fetch the latest version}});// Use the value in another construct withgetParameter.getData('Parameter.Value')
进行api调用所需的iam策略语句是从调用派生的
默认情况下,允许对所有资源执行操作(*
)。你可以
通过使用指定自己的语句列表来限制权限
policyStatements
道具。
链式api调用可以通过创建依赖项来实现:
constawsCustom1=newAwsCustomResource(this,'API1',{onCreate:{service:'...',action:'...',physicalResourceId:'...'}});constawsCustom2=newAwsCustomResource(this,'API2',{onCreate:{service:'...',action:'...'parameters:{text: awsCustom1.getData('Items.0.text')},physicalResourceId:'...'}})