我正在使用Typescript和CDK在AWS中生成新的SNS主题和订阅。除了运行编译(npm run build)之外,还需要在代码中采取其他步骤来在AWS中生成这些对象吗?
以下是一些代码段:
import * as sns from '@aws-cdk/aws-sns';
import * as subs from '@aws-cdk/aws-sns-subscriptions';
let lambda = new Function(this, 'Function', {
runtime: Runtime.NODEJS_10_X,
handler: "src/handler.handler",
code: Code.fromAsset("function"),
role: lambdaRole,
logRetention: RetentionDays.TWO_WEEKS,
logRetentionRole: lambdaRole,
timeout: Duration.seconds(10),
environment,
vpc,
vpcSubnets: {
subnets: subnets
},
securityGroups: [
new SecurityGroup(this, "SG", {
vpc,
allowAllOutbound: true,
description: StackConfiguration.name + "-sg",
securityGroupName: StackConfiguration.name + "-sg",
})
],
functionName: StackConfiguration.name,
allowAllOutbound: true,
description: `Handler for ${StackConfiguration.name} with version ${StackConfiguration.version}`
});
const isProd = StackConfiguration.environmentKey === 'production';
const key = new Key(this, "CustomKey");
key.grantEncryptDecrypt(lambda);
const topic = new sns.Topic(this, "outbound-claim-events-lambda-topic", {
masterKey: key
});
if(isProd) {
topic.addSubscription(new subs.EmailSubscription('xxxxxxxxx'));
} else {
topic.addSubscription(new subs.EmailSubscription('xxxxxxxxx'));
}
topic.grantPublish(lambda)
您需要CDK deploy
在将AWS CLI配置为要将组件部署到的AWS账户时运行。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句