Skip to content

Frequently Asked Questions

S3

  1. 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:

    bash
    export 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/javascript

    Or use @kmp/b7nx:deploy-ng executor to automate the above task so you can just do npx nx deploy admin. Add the following to your project.json/targets

    json
    "deploy": {
        "executor": "@kmp/b7nx:deploy-ng",
        "options": {
            "parameterStore": "/kmp/admin/bucket-name",
            "copyFrom": "dist/packages/admin/browser"
        }
    }

REST and HTTP

  1. 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.

    text
    GET    /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"
  2. I am writing a lambda function, what HTTP response status is available for me to return to the client?

    text
    1xx: 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 side

    See HTTP response status codes for more detailed responses.

DynamoDB

  1. In DynamoDB, when do I use PutItem and when do I use UpdateItem?

    • Use updateItem with attribute_not_exist to create a new item
    • Use updateItem to update the attributes of an existing item
    • Use putItem to create or replace an item entirely
    • Most of the time, updateItem is what you want

testsetset aseta

Made with ❤️ by Bagubagu Studio