in code/csharp/pipelines-workshop/src/CdkWorkshop/HitCounter.cs [20:49]
public HitCounter(Construct scope, string id, HitCounterProps props) : base(scope, id)
{
var table = new Table(this, "Hits", new TableProps
{
PartitionKey = new Attribute
{
Name = "path",
Type = AttributeType.STRING
}
});
MyTable = table;
Handler = new Function(this, "HitCounterHandler", new FunctionProps
{
Runtime = Runtime.NODEJS_14_X,
Handler = "hitcounter.handler",
Code = Code.FromAsset("lambda"),
Environment = new Dictionary<string, string>
{
["DOWNSTREAM_FUNCTION_NAME"] = props.Downstream.FunctionName,
["HITS_TABLE_NAME"] = table.TableName
}
});
// Grant the lambda role read/write permissions to our table
table.GrantReadWriteData(Handler);
// Grant the lambda role invoke permissions to the downstream function
props.Downstream.GrantInvoke(Handler);
}