Tutorial Dojo - DVA-C02 - Timed Mode Set 5

Test time: Dec 9, 2023 (14:30)

Score: 47/65 (72%):

  • CDA – Development with AWS Services 76.92% (20/26)
  • CDA – Security 61.54% (8/13)
  • CDA – Deployment 66.67% (6/9)
  • CDA – Troubleshooting and Optimization 76.47% (13/17)

Domain 1: Development with AWS Services

NoQARef
1Lambda: Debug - Return log stream for the function instanceUse context.logStreamName
2API Gateway & Lambda: New version. Smooth migrationUpdate Lambda function -> Deploy new version. Specify new ARN in API Gateway integration. Redeploy to new stage.
3Elastic Beanstalk: Path of config file/.ebextensions/xxx.config
4Lambda: Ephemeral storage/tmp
5Lambda: How to use Ruby?Ruby’s natively support
6CloudFront: Update image immediatelyUse file name versioning
7Cognito: Authentication with JWT1. Create User Pools
2. Create an authorizer with Cognito User Pool ID
3. Set token source for authorization (to the name of header store JWT)
8X-Ray: Group the traceSubsegment: breakdown segment & provide granular timing detail about downstream calls (to AWS services, HTTP APIs, SQL queries)
Annotations: key-pair values, indexed to used with filter expression 👉 group traces (with console) or call GetTraceSummaries API
Metadata: key-pair values (not-indexed)
9S3: Lowest costGlacier Deep Archive
10EC2: Run Apache web serverUse user-data to install and start Apache web server
11App host in 1 region. Re-create on other regions using AMI & CloudFormation. How?Use Cfn Mapping & FindInMap
12Serverless app. Application code & infrastructure code in Python. How?Use CDK and Python
13Step Functions: Handle error? Aggregate data in different states?Use Catch & ResultPath
14Step Functions: Break a task into multiple tasks (process synchronously)Step Functions state types:1.14
- Do some work: Task State & Parallel State
- Not do some work: Wait State, Pass State, Choice State, Map State, Success/Fail State.
15DynamoDB: Control access to individual items & attributes?Fine-grain access control with1.15
1. IAM policy
2. Condition keys,
2.1 dynamodb:LeadingKeys
2.2 dynamodb:Attributes
3. IAM substitution variable e.g. ${www.amazon.com:user_id}, ${graph.facebook.com:id}, and ${accounts.google.com:sub}
16Cognito: UI for login page missing brand logoCognito allows customization for: logo, CSS.
17SQS queue: messages larger than 256KB.Use Amazon S3, (for Java) Extended Client Library
18Lambda: Provide a public HTTPS endpoint & ensure it executes only if the request’s from valid user1. Use Lambda function URL1.18
2. Auth type:
- AWS_IAM
- NONE: The URL endpoint will be public
3. Implement your own authenticator logic in your function.
19In-house authentication system, support sync user data between devices/platformsCognito Identity Pools - Developer-authenticated identities:
- Use your own authenticated process
- Use Cognito to sync user data between devices/platforms
20API Gateway: Integrate a XML-based SOAP API. How?Use HTTP Integration:
- Integration Request: Map incoming request from JSON to XML (with mapping template)
- Integration Response: Map API response from XML back to JSON (with mapping template)
21Serverless: Send newsletter at 7-day interval. How?Use EventBridge Schedule Rule to create events at 7-day interval, sends the events to Lambda function target
22DynamoDB: Python call BatchGetItem return partial data. Why? Fix?- BatchGetItem use more than the provisioned throughput limit
- To fix this:
1. Increase provisioned throughput
2. Wait for the load to DynamoDB reduces & try again:
- Implement your own retries with exponential backoff algorithm
- Use AWS SDK to call BatchGetItem (comes with retries & exponential backoff)
23DynamoDB: Group multiple actions to multiple items to a one-or-nothing operation?Use TransactionWriteItems
24DynamoDB: When an item added to Customer table, dynamically update Payment table. How do it in real time?Enable DynamoDB Streams for Customer table, trigger a Lambda function to update Payment table
25ALB: Obtain all value of identical query parameter key.Enable multi-value headers
26ECS: 2 containers share logs. How?Define these 2 containers in 1 task definition, use EFS as a volume

Domain 2: Security

NoQARef
1S3: Encryption each files with different keys. Cost-effective, low overhead- SSE-S3: use the same key for all files.
- SSE-C & use KMS to create CMK for each files (CreateKey): not cost-effective (1CMK: 1$/month)
- SSE-KMS & Use KMS to generate DEK for each files (GenerateDataKey): 👈 THIS
2S3 bucket in production account. How to allow a user on dev account access?1. In prod acc, create an IAM role2.2
1.1 Give it just enough permission for its task)
2.2 Specify the dev account as a trusted entity
2. In dev acc, allow it to assume role of prod acc (created in step 1)
3. In dev acc, switch role to prod acc
3S3. Which service to allow user register/sign-in & upload/access images on S3.Cognito User Pools & Identity Pools
4Allow temporary access to EC2 & but still enforce MFA? Which STS API?STS GetSessionToken
5KMS features
6API Gateway: Regulate access to API & charge based on usageUsage Plan
7Best practice to manage access keyRemote all access key of root account, use IAM role for applications
8Most secure way to send CW logs in EC2 instance of ASG launch configuration- Create a new IAM role for the new Launch Configuration
- Launch Configuration (deprecated), use Launch Template.
9AWS CLI: UnauthorizedOperation error with encoded authorization message. What to do?Decode the message with STS decode-authorization-message2.9
10S3: Hundreds of thousands of objects. Turn on SSE-KMS. Performance degradation. Why?Requests to KMS are exceeded quota
11How to check permission of an IAM role?1. Use IAM Policy Simulator
2. Run AWS CLI with --dry-run
12Serverless app defined with Cloud Development Kit (CDK). How to test local?1. (From CDK template) “Synthesize” & output Cfn template with cdk synth2.12 What is CDK? 2.12 CDK toolkit commands
2. Invoke the Lambda function locally with sam invoke local (by emulating the Lambda execution environment.)2.12 sam local invoke
13Cognito Identity Pools: What does Cognito returns to authenticated/unauthenticated user?- For authenticated users: Cognito returns the token
- For unauthenticated users: Cognito returns a Cognito ID

2.4 Requesting temporary security credentials with Security Token Service (STS)

STS TokenWhat it does?Notes
AssumeRolecross-account delegation and federation through a custom identity brokerCross-account, MFA
AssumeRoleWithWebIdentityfederation through a web-based identity providerSSO
AssumeRoleWithSAMLfederation through an enterprise Identity Provider compatible with SAML 2.0
GetFederationTokenfederation through a custom identity brokerProxy app
GetSessionTokentemporary credentials for users in untrusted environmentsMFA

Ref:

2.5 KMS features

KMS features:

  • Create symmetric/asymmetric keys
  • Import symmetric keys
  • Rotate symmetric keys
  • Disable/Enable keys

Not a KMS features:

  • Import asymmetric keys
  • Rotate key in custom stores

Domain 3: Deployment

NoQARef
1CodeDeploy: S3 source. Deploy to EC2 fail during DownloadBundleThe EC2 instance profile don’t have permission to access S3 bucket
2CodeDeploy: RollbackCodeDeploy rolls back deployments by redeploying a previously deployed revision of an application as a new deployment (with new deployment ID)3.2
3Deploy to 3 environments: test, staging, production. How?Use 3 deployment groups, each for 1 environment.
4Elastic Beanstalk: Multi-container Docker. Which file to configure container definitions?Dockerrun.aws.json
5Elastic Beanstalk: Multi developers deploy without upload the whole project?Use eb deploy to deploy from local CodeCommit repo
6Serverless app defined with CDK. Deploy to new account. NoSuchBucket error. Fix?Run cdk bootstrap to provision resources for CDK deployment, e.g. IAM role, S3 bucket.
7CodeCommit: How to setup for a new user?Use AWS credential (with credential-helper)3.7
8CodeCommit: Forgot to pull master. Fix conflict?git rebase feature branch on master branch. Then manually fix conflict.
9SAM: How to deploy (& test)?1. (Once time) sam init
2. sam deploy

3.7 CodeCommit: Setup for new user

  • HTTPs Git credential (use username & password)

  • SSH connections (use public-private key pair)

    • Create public & private key pair on your local machine
    • Associate the public key with IAM user
  • Use AWS credential (profile)

    1. Use git-remote-commit (recommended)
    2. Use aws codecommit credential-helper

Domain 4: Troubleshooting and Optimization

NoQARef
1Lambda: Function created with Cfn doesn’t send logs to CW?Modify ExecutionRole & add AWSLambdaBasicExecutionRole managed policy
- (Attach to Lambda’s resourced-based policy won’t works)
- When created with Web Console, the console automatically add these policy to execution role for us
- With Cfn, we need to do it ourself.
2ECS: EC2 launch type. Terminate an instance (after it’s stopped), but the container instance still appear in ECS clusterTerminate an instance:
- In running state, it will be automatically deregistered with ECS cluster
= In stopped state, it won’t be
3CodeBuild: Run on a proxy server. RequestError when CodeBuild is accessed. Fix?
4API Gateway: Enable API caching. How to test the function without caching?0. Create a resource-based policy to allows the API Gateway execution service to invalidate the cache for requests on the specified resource4.4
1. Make a request with Cache-Control: max-age=0 header
5S3 - Event Notifications: Compress the images, but it takes too much time. Improve?Increase memory ➡️ increase CPU
6Debug latency of your app (with recently added function)? How to do with X-Ray?Define sug-segments inside the function to “instrument” (measure) it
7AWS CLI: Create snapshot of EC2 instance. InvalidInstanceID.NotFound. Why?Maybe the AWS CLI is using a profile for a different region
8Build a CI pipeline. Which AWS services?CodeCommit, Lambda, CodeBuild
9Step Functions: Handle & recover from State’s exception.Use Catch & Retry fields in state machine definition
10Lambda - Cold start: Optimize?1. Reduce pre-handler code
2. Increase CPU (by increasing memory)
11LAMP stack. Migrate to AWS?EC2 + Aurora/RDS
12Lambda: process file (5min). So slow?Change InvokeType to Event (asynchronous invocation)
13DynamoDB: Optimize Scan in low-demand time?Parallel scan: distribute workload across the partitions of the table (by passing Segment and TotalSegments parameters into the Scan operation)4.13
14Website (hosted on S3) call API Gateway. No "Access-Control-Allow-Origin" error. Fix?Config CORS for API Gateway to allow the website (S3)
15API Gateway + Lambda: Publish a new version of AccService:Prod with the alias AccService:Beta. How to test before promote?Create a BETA stage. Use stage variable to reference the beta function alias
16Lambda: Unable to import module. Fix?1. Install the missing module locally.
2. Package it with the handler or in a layer
3. Re-upload to Lambda
17Elastic Beanstalk: Keep the old code in S3 bucket. How?Change Retention to Retain source bundle in S3