AWS Lambda CDK 不生成 SNS 主题和订阅
AWS Lambda CDK does not generate SNS topic and subscription
我正在使用 Typescript 和 CDK 在 AWS 中生成新的 SNS 主题和订阅。除了 运行 编译(npm 运行 构建)之外,是否还需要在代码中执行其他步骤才能在 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 账户。
我正在使用 Typescript 和 CDK 在 AWS 中生成新的 SNS 主题和订阅。除了 运行 编译(npm 运行 构建)之外,是否还需要在代码中执行其他步骤才能在 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 账户。