Allow lambda security group access to cache security group in CDK stack #109
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #108
What I did:
Granted the lambda's security group access to the cache's security group through CDK.
How I did it:
I created a custom security group in the lambda function's VPC, and directly attached this security group to the (using the
security_groups:[]
property of theaws_lambda.Function
class - this skips the automatic creation adefault
security group in the VPC.I was then able to grant the lambda 's custom security group access to the cache security group (using the
ec2.SecurityGroup.add_ingress_rule()
property) so that the lambda function has access to the cache.How you can test it:
Running this code snippet for the first time:
produces the following output:
Notice that:
/datasets
request takes ~4 secondsRunning the code snippet a second time produces:
Notice that:
/datasets
request takes ~0.2 seconds'X-Cache': 'HIT'
**Note: **
vpc_access_policy_statement
statement intovpc_log_access
andvpc_ec2_access
for clarityiam_policy_statement
tos3_full_access_to_data_bucket
for clarity