AWS Lambda CDK does not generate SNS topic and subscription

Viewed 674

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)
1 Answers

You will need to run a CDK deploy While having your AWS CLI configured to the AWS account you want to deploy the components to.

Related