Section 21: AWS Serverless: Lambda: Part 2 Flashcards
What does the lambda execution role do, and what are some (the answer list is just a sample) managed policies for lambda? (also, yes, many of these managed policies having names ending in *Role)
- it grants the lambda function permissions to aws services/resources
* AWSLambdaBasicExecutionRole (upload logs to cloudwatch)
* AWSLambdaKinesisExecutionRole (read from kinesis)
* AWSLambdaDynamoDBExecutionRole (read from dynamoDB streams)
* AWSLambdaSQSQueueExecutionRole (read from sqs)
* AWSLambdaVPCAccessExecutionRole (deploy lambda function in vpc)
* AWSXRayDaemonWriteAccess (upload trace data to xray)
note that when you use an event source mapping to invoke your function, lambda uses the execution role to read event data. that’s why some of the names above say ‘Execution’ when the descriptions say ‘read’
What does amazon say is best practice for ratio of lambda execution roles to functions?
one Lambda Execution Role to one function. Also, note that the managed policy AWSLambdaVPCAccessExecutionRole is actually a policy, i’m not sure it’s a role. maybe look into what’s going on there later. i don’t think roles and policies are the same thing, i think roles contain policies. So i’m betting that either this suggestion means that you use their managed policy in a role you make for a specific function.
Should you use resource based policies to give other accounts and aws services permission to use your lambda resource?
Yes. that policy appears to be created in the lambda function area (if you’re using the console). I think they’re saying the whole thing works similarly to the way it works for S3 bucket policies for S3 bucket.
an iam principal can access lambda if blank 1 or if blank 2
- the iam policy attached to the principal authorizes it (ex: user access)
- the resource-based policy authorizes (ex: service access)
When an aws service like s3 calls your lambda function, who gives it (s3, i presume) access?
the resource based policy (that, again, i beleive is from the lambda side of things)
- Can you create lambda environment variables?
- does lambda service add it’s own system env vars as well?
- The slides say that env vars can be helpful for storing secrets (or that’s what it seems like they’re saying), but what does aws say?
- are all env vars (values) considered literal strings?
- yes
- yes
- aws says you prob want to use AWS Secrets Manager instead
- yes
Lambda and CloudWatch
Are lambda execution logs stored in aws CloudWatch logs?
yes
If for some reason lambda execution logs aren’t being stored in CloudWatch Logs, what might be going on? (honestly maybe you’d get an error sayig exactly what’s happening, idk)
You need to make sure your aws lambda function has an execution role wil iam policy that authorizes writes to CloudWatch Logs.
Are lambda metrics automatically sent to CloudWatch Metrics, free of charge?
yep. in one minute intervals. if you want them send faster, build a custom metric (that will start incurring cost, though)
Where are AWS Lambda metrics displayed, and what are some of the lambda metrics that get displayed there?
- invocations
- durations
- concurrent executions
- error count
- success rates
- throttles
- async delivery failures
- iterator age (kinesis and dynamoDB streams)
Lamnda Monitoring and CloudWatch
lambda tracing with xray
Where are Lambda execution logs stored?
lambda exeuction logs are stored in aws CloudWatch Logs.
How do you get lambda tracing to work with xray in the console and in the code?
- in the console: enable Active Tracing in Lambda. This runs the X-Ray daemon for you.
- in code: use aws xray sdk in code
- ensure lambda function has a correct iam execution role
What’s the name of the managed policy you can use to get lambda tracing with xray?
AWSXRayDaemonWriteAccess
What are the environment variables needed for lambda (it seems like any service really) to chat with xray?
- _X_AMZN_TRACE_ID
- AWS_XRAY_CONTEXT_MISSING (by default, LOG_ERROR)
- AWS_XRAY_DAEMON_ADDRESS (the x-ray daemon IP_ADDRESS:PORT )
- So an edge function is code that you write and attach to CloudFront distributions. It runs close to your users why?
- CloudFront provides two types of edge functions. What and what?
- To minimize latency.
- CloudFront Functions & Lambda@Edge