Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import { Build } from 'punchcard/lib/core/build';
export const app = new Core.App();
const stack = app.root.map(app => new cdk.Stack(app, 'invoke-function-example'));
const table = new DynamoDB.Table(stack, 'my-table', {
partitionKey: 'id',
attributes: {
id: string(),
count: integer({
minimum: 0
}),
anyProperty: dynamic
},
tableProps: Build.of({
billingMode: BillingMode.PAY_PER_REQUEST
})
});
// create a function that increments counts in a dynamodb table
// Function
const incrementer = new Lambda.Function(stack, 'Callable', {
// request is a structure with a single property, 'id'
request: struct({
id: string()
}),
// response is just an integer
response: integer(),
depends: table.readWriteAccess(),
}, async (request, table) => {
console.log(request);
const item = await table.get({
}
type Query {
all(limit: Int, nextToken: String): Paginated${tableName}!
getOne(${tableName}Id: ID!): ${tableName}
}
type Mutation {
save(name: String!): ${tableName}
delete(${tableName}Id: ID!): ${tableName}
}
type Schema {
query: Query
mutation: Mutation
}`
});
const itemsTable = new Table(this, 'ItemsTable', {
tableName: tableName,
partitionKey: {
name: `${tableName}Id`,
type: AttributeType.STRING
},
billingMode: BillingMode.PAY_PER_REQUEST,
stream: StreamViewType.NEW_IMAGE,
// The default removal policy is RETAIN, which means that cdk destroy will not attempt to delete
// the new table, and it will remain in your account until manually deleted. By setting the policy to
// DESTROY, cdk destroy will delete the table (even if it has data in it)
removalPolicy: cdk.RemovalPolicy.DESTROY, // NOT recommended for production code
});
const itemsTableRole = new Role(this, 'ItemsDynamoDBRole', {
assumedBy: new ServicePrincipal('appsync.amazonaws.com')
constructor(scope: cdk.Construct, id: string, props: property) {
super(scope, id, props);
const lambdaRole = props.lambdaRoleARN
? iam.Role.fromRoleArn(this, "LambdaRole", props.lambdaRoleARN, {
mutable: false,
})
: undefined;
const sfnRole = props.sfnRoleARN
? iam.Role.fromRoleArn(this, "SfnRole", props.sfnRoleARN, {
mutable: false,
})
: undefined;
this.cacheTable = new dynamodb.Table(this, "cacheTable", {
billingMode: dynamodb.BillingMode.PAY_PER_REQUEST,
partitionKey: { name: "pk", type: dynamodb.AttributeType.STRING },
sortKey: { name: "sk", type: dynamodb.AttributeType.STRING },
timeToLiveAttribute: "expires_at",
});
// ----------------------------------------------------------------
// Messaging Channels
this.alertTopic = new sns.Topic(this, "alertTopic");
this.taskTopic = new sns.Topic(this, "taskTopic");
this.contentTopic = new sns.Topic(this, "contentTopic");
this.attributeTopic = new sns.Topic(this, "attributeTopic");
this.reportTopic = new sns.Topic(this, "reportTopic");
const alertQueueTimeout = cdk.Duration.seconds(30);
this.alertQueue = new sqs.Queue(this, "alertQueue", {
const changelogsTable = new dynamodb.Table(this, 'Changelogs', {
partitionKey: { name: 'changelog', type: dynamodb.AttributeType.STRING },
billingMode: dynamodb.BillingMode.Provisioned
});
const readScaling = changelogsTable.autoScaleReadCapacity({
minCapacity: 211,
maxCapacity: 300
});
readScaling.scaleOnUtilization({
targetUtilizationPercent: 75
});
// A table to store the list of feeds
const feedsTable = new dynamodb.Table(this, 'Feeds', {
partitionKey: { name: 'feed', type: dynamodb.AttributeType.STRING },
billingMode: dynamodb.BillingMode.PayPerRequest
});
// A table which stores the auto complete search index
const searchIndexTable = new dynamodb.Table(this, 'search-index', {
partitionKey: { name: 'fragment', type: dynamodb.AttributeType.STRING },
sortKey: { name: 'score', type: dynamodb.AttributeType.STRING },
timeToLiveAttribute: 'validUntil',
billingMode: dynamodb.BillingMode.PayPerRequest
});
// An S3 bucket which holds the web content
const webBucket = new s3.Bucket(this, 'web-bucket', {
publicReadAccess: true,
websiteIndexDocument: 'index.html'
// Create an ECS cluster
this.cluster = new ecs.Cluster(this, 'cluster', {
vpc: this.vpc
});
// Create S3 bucket
this.screenshotBucket = new s3.Bucket(this, 'screenshot-bucket', {
publicReadAccess: true
});
// Create queue
this.screenshotQueue = new sqs.Queue(this, 'screenshot-queue');
// Create DynamoDB table
this.screenshotTable = new dynamodb.Table(this, 'screenshots', {
partitionKey: { name: 'id', type: dynamodb.AttributeType.String },
billingMode: dynamodb.BillingMode.PayPerRequest
});
}
}
constructor(parent, id, props) {
super(parent, id, props);
// Network to run everything in
const vpc = new ec2.Vpc(this, 'NpmFollowerVpc', {
maxAZs: 2,
natGateways: 1
});
// A table to store the list of changelogs and their metadata in
const changelogsTable = new dynamodb.Table(this, 'Changelogs', {
partitionKey: { name: 'changelog', type: dynamodb.AttributeType.STRING },
billingMode: dynamodb.BillingMode.Provisioned
});
const readScaling = changelogsTable.autoScaleReadCapacity({
minCapacity: 211,
maxCapacity: 300
});
readScaling.scaleOnUtilization({
targetUtilizationPercent: 75
});
// A table to store the list of feeds
const feedsTable = new dynamodb.Table(this, 'Feeds', {
partitionKey: { name: 'feed', type: dynamodb.AttributeType.STRING },
minCapacity: 211,
maxCapacity: 300
});
readScaling.scaleOnUtilization({
targetUtilizationPercent: 75
});
// A table to store the list of feeds
const feedsTable = new dynamodb.Table(this, 'Feeds', {
partitionKey: { name: 'feed', type: dynamodb.AttributeType.STRING },
billingMode: dynamodb.BillingMode.PayPerRequest
});
// A table which stores the auto complete search index
const searchIndexTable = new dynamodb.Table(this, 'search-index', {
partitionKey: { name: 'fragment', type: dynamodb.AttributeType.STRING },
sortKey: { name: 'score', type: dynamodb.AttributeType.STRING },
timeToLiveAttribute: 'validUntil',
billingMode: dynamodb.BillingMode.PayPerRequest
});
// An S3 bucket which holds the web content
const webBucket = new s3.Bucket(this, 'web-bucket', {
publicReadAccess: true,
websiteIndexDocument: 'index.html'
});
// An S3 bucket which holds the API content
const apiBucket = new s3.Bucket(this, 'api-bucket', {
publicReadAccess: true,
websiteIndexDocument: 'index.json'
const lambdaRole = props.lambdaRoleARN
? iam.Role.fromRoleArn(this, "LambdaRole", props.lambdaRoleARN, {
mutable: false,
})
: undefined;
const sfnRole = props.sfnRoleARN
? iam.Role.fromRoleArn(this, "SfnRole", props.sfnRoleARN, {
mutable: false,
})
: undefined;
this.cacheTable = new dynamodb.Table(this, "cacheTable", {
billingMode: dynamodb.BillingMode.PAY_PER_REQUEST,
partitionKey: { name: "pk", type: dynamodb.AttributeType.STRING },
sortKey: { name: "sk", type: dynamodb.AttributeType.STRING },
timeToLiveAttribute: "expires_at",
});
// ----------------------------------------------------------------
// Messaging Channels
this.alertTopic = new sns.Topic(this, "alertTopic");
this.taskTopic = new sns.Topic(this, "taskTopic");
this.contentTopic = new sns.Topic(this, "contentTopic");
this.attributeTopic = new sns.Topic(this, "attributeTopic");
this.reportTopic = new sns.Topic(this, "reportTopic");
const alertQueueTimeout = cdk.Duration.seconds(30);
this.alertQueue = new sqs.Queue(this, "alertQueue", {
visibilityTimeout: alertQueueTimeout,
});
this.alertTopic.addSubscription(new SqsSubscription(this.alertQueue));
super(scope, id, props);
const lambdaRole = props.lambdaRoleARN
? iam.Role.fromRoleArn(this, "LambdaRole", props.lambdaRoleARN, {
mutable: false,
})
: undefined;
const sfnRole = props.sfnRoleARN
? iam.Role.fromRoleArn(this, "SfnRole", props.sfnRoleARN, {
mutable: false,
})
: undefined;
this.cacheTable = new dynamodb.Table(this, "cacheTable", {
billingMode: dynamodb.BillingMode.PAY_PER_REQUEST,
partitionKey: { name: "pk", type: dynamodb.AttributeType.STRING },
sortKey: { name: "sk", type: dynamodb.AttributeType.STRING },
timeToLiveAttribute: "expires_at",
});
// ----------------------------------------------------------------
// Messaging Channels
this.alertTopic = new sns.Topic(this, "alertTopic");
this.taskTopic = new sns.Topic(this, "taskTopic");
this.contentTopic = new sns.Topic(this, "contentTopic");
this.attributeTopic = new sns.Topic(this, "attributeTopic");
this.reportTopic = new sns.Topic(this, "reportTopic");
const alertQueueTimeout = cdk.Duration.seconds(30);
this.alertQueue = new sqs.Queue(this, "alertQueue", {
visibilityTimeout: alertQueueTimeout,
});
const fargateTaskRole = fargatesvc.service.taskDefinition.taskRole;
fargateTaskRole.addToPolicy(new iam.PolicyStatement({
resources: ['*'],
actions: ['events:*']
}));
const orderTable = new dynamodb.Table(this, 'Order', {
partitionKey: { name: 'seqNo', type: dynamodb.AttributeType.NUMBER },
billingMode: dynamodb.BillingMode.PAY_PER_REQUEST,
tableName: 'Order',
});
orderTable.grantFullAccess(fargateTaskRole);
const coffeeTable = new dynamodb.Table(this, 'Coffee', {
partitionKey: { name: 'seqNo', type: dynamodb.AttributeType.NUMBER },
billingMode: dynamodb.BillingMode.PAY_PER_REQUEST,
tableName: 'Coffee',
});
coffeeTable.grantFullAccess(fargateTaskRole);
const rule = new Rule(this, 'OrderCreatedRule',{
eventPattern:{
source:["solid.humank.coffeeshop.order"],
detailType:['customevent']
},
// eventBus: coffeeshop_eventbus,
ruleName: 'OrderCreatedRule',
});
//add ssm parameter store for cloudwatchevent put usage