Frequently Asked Questions
S3
My website is on Cloudfront with S3 origin. When I go to http://my.web.site it downloads the document instead of serving my index.html. How do I fix this?
Most likely cause is because your index.html contains the wrong content-type information. To sync your distribution output with S3 with the correct content-types:
bashexport projectName=admin export distDir=./dist/packages/${projectName}/browser export bucketName=my-target-s3-bucket aws s3 sync ${distDir} s3://${bucketName} --delete aws s3 cp ${distDir}/index.html s3://${bucketName} --content-type text/html aws s3 sync ${distDir}/ s3://${bucketName} --exclude "*" --include "*.css" --content-type text/css aws s3 sync ${distDir}/ s3://${bucketName} --exclude "*" --include "*.js" --content-type application/javascriptOr use
@kmp/b7nx:deploy-ngexecutor to automate the above task so you can just donpx nx deploy admin. Add the following to yourproject.json/targetsjson"deploy": { "executor": "@kmp/b7nx:deploy-ng", "options": { "parameterStore": "/kmp/admin/bucket-name", "copyFrom": "dist/packages/admin/browser" } }
REST and HTTP
When designing a REST API, when do I use PUT and when do I use POST?
Use POST to create a new item, PUT for an idempotent update to an existing item, and PATCH to update some of the item information.
textGET /tenants // Get all tenants POST /tenants // Create a new tenant GET /tenants/{id} // Get detail of tenant identified by "id" PUT /tenants/{id} // Update the tenant identified by "id" entirely PATCH /tenants/{id} // Update some of the tenant information DELETE /tenants/{id} // Delete tenant by "id"I am writing a lambda function, what HTTP response status is available for me to return to the client?
text1xx: Informational - Communicates transfer protocol-level information 2xx: Success - Request was accepted succesfully 3xx: Redirection - Client must take some additional action in order to complete their request 4xx: Client Error - There is an error with the client's request 5xx: Server Error - There is an error on the server sideSee HTTP response status codes for more detailed responses.
DynamoDB
In DynamoDB, when do I use PutItem and when do I use UpdateItem?
- Use
updateItemwithattribute_not_existto create a new item - Use
updateItemto update the attributes of an existing item - Use
putItemto create or replace an item entirely - Most of the time, updateItem is what you want
- Use
testsetset aseta