Realized I've accumulated a collection of little s...
# sst
d
Realized I've accumulated a collection of little scripts to help patch up things that CDK and/or SST don't easily provide, might be useful to others:
Copy code
# API GW: Set up throttling and metrics
aws apigatewayv2 update-stage \
    --api-id xxx \
    --stage-name '$default' \
    --default-route-settings '{"ThrottlingBurstLimit":10,"ThrottlingRateLimit":50,"DetailedMetricsEnabled":true}'


# CFN: fix stupidity. See <https://github.com/serverless-stack/serverless-stack/issues/125>
aws logs put-resource-policy --policy-name AWSLogDeliveryWrite20150319 --policy-document "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Sid\":\"AWSLogDeliveryWrite\",\"Effect\":\"Allow\",\"Principal\":{\"Service\":\"<http://delivery.logs.amazonaws.com|delivery.logs.amazonaws.com>\"},\"Action\":[\"logs:CreateLogStream\",\"logs:PutLogEvents\"],\"Resource\":[\"*\"]}]}"


# Aurora: enable Performance Insights on every instance. If needed: brew install jq
aws rds describe-db-instances --query 'DBInstances[*].[DBInstanceIdentifier]' \
        | jq -r '.[]' | jq -r '.[]' \
        | xargs -J % -L1 \
        aws rds modify-db-instance \
            --db-instance-identifier % \
            --enable-performance-insights
Given that log groups aren't deleted with CFN stack, might repurpose that last script to clean up logs after removing a stack
f
I noticed CDK will be adding an option to
lambda.Function
to set the retain policy for the Lambda log group. That will allow setting the log groups to be deleted on stack removal.
And to set up the API throttling and metrics in CDK, you can do something like this before CDK adds high level support for it:
Copy code
const api = new sst.Api(...);
api.httpApi.defaultStage.node.defaultChild.defaultRouteSettings = {
  throttlingBurstLimit: 10,
  throttlingRateLimit: 50,
  detailedMetricsEnabled: true,
};
api.httpApi.defaultStage.node
give you the CloudFormation object for the default stage. This lets you edit the raw CF template.
d
ah nice! ty. I tried jumping up and down the nodes but didn't feel confident to change from there
d
Nice. so that's how you set the throttle limits!
r
@Frank I have issue for api.httpApi.defaultStage.node.defaultChild.defaultRouteSettings: TS2339: Property 'defaultRouteSettings' does not exist on type 'IConstruct'.
f
Try casting
api.httpApi.defaultStage.node.defaultChild as CfnStage
And you can import
CfnStage
like this:
Copy code
import { CfnStage } from "@aws-cdk/aws-apigatewayv2";
r
@Frank thanks