I am using Typescript and a CDK to generate a new SNS topic and subscription in AWS. Other than running a compile (npm run build) are there other steps that need to be taken in the code to generate these objects in AWS?
Here are some code snippets:
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 账户。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.