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 the aws_lambda.Function class - this skips the automatic creation a default 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:
for e in ["", "global", "du", "be", "tk","la", "sf", "ny", "gl"]:
start = time.time()
r = re.get(f"https://08dvkxus0a.execute-api.us-east-1.amazonaws.com/v1/datasets/{e}") # staging url
end = time.time()
print(f"Requested: /{e}, response time: {str(end-start)}, Response headers: {r.headers}")
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