Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import * as AmplifyHelpers from '@aws-amplify/cli-extensibility-helper';
- import * as ev from '@aws-cdk/aws-events';
- import * as et from '@aws-cdk/aws-events-targets';
- import * as lambda from '@aws-cdk/aws-lambda';
- import * as ssm from '@aws-cdk/aws-ssm';
- import * as cdk from '@aws-cdk/core';
- import * as cr from '@aws-cdk/custom-resources';
- import { AmplifyDependentResourcesAttributes } from '../../types/amplify-dependent-resources-ref';
- export class cdkStack extends cdk.Stack {
- constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps, amplifyResourceProps?: AmplifyHelpers.AmplifyResourceProps) {
- super(scope, id, props);
- // CloudFormation complains if I move this in values-stack with
- // "Parameter values specified for a template which does not require them."
- new cdk.CfnParameter(this, 'env', {
- type: 'String',
- description: 'Current Amplify CLI env name',
- });
- const busName = new ssm.StringParameter(this, `reservationbusname`, {
- stringValue: `busname`,
- dataType: ssm.ParameterDataType.TEXT,
- }).stringValue;
- const ruleName = new ssm.StringParameter(this, `reservationrulename`, {
- stringValue: `busrule`,
- dataType: ssm.ParameterDataType.TEXT,
- }).stringValue;
- const sourcePar = new ssm.StringParameter(this, `reservationbussourcename`, {
- stringValue: `my.source`,
- dataType: ssm.ParameterDataType.TEXT
- });
- const source = sourcePar.stringValue;
- const deps: AmplifyDependentResourcesAttributes = AmplifyHelpers.addResourceDependency(this,
- amplifyResourceProps.category,
- amplifyResourceProps.resourceName,
- [
- { category: "function", resourceName: "lambda1" },
- { category: "function", resourceName: "lambda2" }
- ]
- );
- const lambda1Arn = cdk.Fn.ref(deps.function.lambda1.Arn);
- const lambda2Arn = cdk.Fn.ref(deps.function.lambda1.Arn);
- const eventBus = new ev.EventBus(this, `reservationbus`, {
- eventBusName: busName
- });
- const lambda1 = lambda.Function.fromFunctionArn(this,
- `lambda1id`,
- lambda1Arn);
- eventBus.grantPutEventsTo(lambda1);
- const lambda2 = lambda.Function.fromFunctionAttributes(this, `lambda2`, {
- functionArn: lambda2Arn,
- sameEnvironment: true
- });
- const rule = new ev.Rule(this, `rule-id`, {
- ruleName: ruleName,
- eventBus: eventBus,
- eventPattern: {
- source: [source],
- },
- targets: [
- new et.LambdaFunction(lambda1)
- ],
- });
- et.addLambdaPermission(rule, lambda1);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment