Skip to main content

aws questions

 1)Types of aws sqs?

ans:

Amazon Simple Queue Service (SQS) offers two main types of queues: Standard Queues and FIFO (First-In-First-Out) Queues. Here's an overview of each:


Standard Queues:

Standard Queues offer best-effort ordering, which means that messages are generally delivered in the order they are sent, but occasionally, out-of-order delivery may occur.

They provide high throughput, with the ability to process a large number of messages per second.

Standard Queues offer at-least-once message delivery, which means that a message can be delivered more than once (but not skipped).

They are suitable for use cases where strict message ordering is not required or where messages can be processed out of order without causing issues.

FIFO (First-In-First-Out) Queues:

FIFO Queues provide exactly-once message processing and ordered message delivery. Messages are delivered in the order they are sent, and each message is delivered exactly once.

They are designed for applications that require strict message ordering or where message duplication or out-of-order delivery is not acceptable.

FIFO Queues have lower throughput compared to Standard Queues and may be subject to higher message processing times due to the strict ordering guarantee.

They are suitable for use cases such as financial transactions, where message order and delivery reliability are critical.

Additionally, both types of queues offer features such as message retention, visibility timeout, dead-letter queues, and message delay, which can be configured to meet specific application requirements.


When choosing between Standard and FIFO Queues in AWS SQS, consider your application's requirements for message ordering, delivery reliability, and throughput to determine the most appropriate queue type.

2)In api gateway how to manipulate lambda output?

Ans:

In API Gateway, you can manipulate the output of a Lambda function using Integration Response templates. These templates allow you to transform the response from your Lambda function before it's sent back to the client making the request. Here's how you can manipulate the Lambda output in API Gateway:


Integration Response: In the API Gateway console, navigate to your API and select the resource/method you want to configure. Under "Integration Response," you'll find the mapping templates.

Mapping Templates: Create or modify a mapping template for the appropriate response status code (e.g., 200 for successful responses). Mapping templates use Velocity Template Language (VTL) to manipulate the response.

VTL Syntax: Use VTL syntax to access and transform the response data from your Lambda function. For example, you can access the body of the response using $input.body, modify it as needed, and set it as the new response body using $util.escapeJavaScript() or other utility functions.

Example:

Suppose your Lambda function returns a JSON object like this:

json

Copy code

{

    "message": "Hello, world!",

    "timestamp": 1620253147000

}

And you want to modify the response to include only the message and the length of the message:

json

Copy code

{

    "message": "Hello, world!",

    "messageLength": 13

}

You can achieve this by creating a mapping template with the following VTL code:

vtl

Copy code

#set($response = $input.path('$'))

#set($messageLength = $response.message.length())

{

    "message": "$response.message",

    "messageLength": $messageLength

}

Testing: After saving the mapping template, deploy your API changes and test the endpoint to verify that the Lambda output is being manipulated as expected.

By using Integration Response templates in API Gateway, you can dynamically transform the output of your Lambda function to meet the requirements of your API clients.


3)

    "aws-sdk": "^2.892.0",

4)AWS lambda to call sync vs async ?
Ans:

In the AWS SDK for Node.js, you can call AWS Lambda functions synchronously or asynchronously using different methods. Here's how you can do it:


Synchronous Invocation:

To invoke a Lambda function synchronously, use the invoke method with the InvocationType parameter set to "RequestResponse". This method waits for the function execution to complete and returns the result or error.Example:

javascript

Copy code

const AWS = require('aws-sdk');

const lambda = new AWS.Lambda();


const params = {

    FunctionName: 'myLambdaFunction',

    InvocationType: 'RequestResponse',

    Payload: JSON.stringify({ /* payload data */ })

};


lambda.invoke(params, (err, data) => {

    if (err) {

        console.error(err);

    } else {

        console.log(data.Payload);

    }

});

Asynchronous Invocation:

To invoke a Lambda function asynchronously, use the invoke method with the InvocationType parameter set to "Event". This method returns immediately after triggering the function without waiting for the execution to complete.Example:

javascript

Copy code

const AWS = require('aws-sdk');

const lambda = new AWS.Lambda();


const params = {

    FunctionName: 'myLambdaFunction',

    InvocationType: 'Event',

    Payload: JSON.stringify({ /* payload data */ })

};


lambda.invoke(params, (err, data) => {

    if (err) {

        console.error(err);

    } else {

        console.log('Lambda function invoked asynchronously');

    }

});

Using these methods, you can choose whether to call Lambda functions synchronously or asynchronously based on your application requirements. Synchronous invocation is useful when you need to wait for the function result, while asynchronous invocation is suitable for fire-and-forget tasks or when you don't need the result immediately.

5)If we trigger lambda from s3 how will be the call sync or async?

ans:

When you trigger a Lambda function from an S3 event, the invocation of the Lambda function is asynchronous. This means that when an object is created, updated, or deleted in an S3 bucket, an event is generated and sent to AWS Lambda, which then triggers the execution of the Lambda function.


The Lambda function is invoked asynchronously, meaning that the S3 event triggers the Lambda function, and Lambda processes the event as soon as resources are available, but there is no direct response to the caller waiting for the Lambda function to complete its execution. Instead, Lambda processes the event in the background without waiting for a response, and the S3 event processing continues asynchronously.


6)How is bucket configuration done with dyamic values in serverless framework based on env?

Ans:

In the Serverless Framework, you can use environment variables to configure dynamic values for your AWS S3 buckets based on different environments (e.g., development, staging, production). You can define environment variables in your serverless.yml file and reference them in your bucket configuration.


Here's how you can achieve dynamic bucket configuration based on environment using the Serverless Framework:


Define Environment Variables: Define environment-specific variables in the provider.environment section of your serverless.yml file. You can define different values for each environment (e.g., dev, staging, prod).

Define Environment Variables: Define environment-specific variables in the provider.environment section of your serverless.yml file. You can define different values for each environment (e.g., dev, staging, prod).

yaml

Copy code

provider:

  name: aws

  runtime: nodejs14.x

  stage: ${opt:stage, 'dev'}

  region: us-east-1

  environment:

    BUCKET_NAME: ${self:custom.bucketName.${self:provider.stage}}


custom:

  bucketName:

    dev: my-dev-bucket

    staging: my-staging-bucket

    prod: my-prod-bucket

Reference Environment Variables: Reference the environment variables in your bucket configuration. Use the ${env:VARIABLE_NAME} syntax to reference environment variables.

yaml

Copy code

resources:

  Resources:

    MyS3Bucket:

      Type: 'AWS::S3::Bucket'

      Properties:

        BucketName: ${env:BUCKET_NAME}

In this example:


We define environment-specific bucket names in the provider.environment section using the ${self:custom.bucketName.${self:provider.stage}} syntax, which references the stage variable to determine the environment-specific bucket name.

We then reference the BUCKET_NAME environment variable in the bucket configuration using ${env:BUCKET_NAME}.

When you deploy your Serverless application using the Serverless Framework, it will use the environment-specific bucket name based on the stage/environment you specify. For example, if you deploy with --stage staging, it will use the my-staging-bucket value for the BUCKET_NAME environment variable.


This approach allows you to dynamically configure S3 bucket names based on different environments while using the same Serverless configuration file (serverless.yml).

7)What is ssm then?

SSM stands for AWS Systems Manager, which is a service that allows you to manage and automate administrative tasks across your AWS resources. AWS Systems Manager provides a centralized way to view and control your infrastructure on AWS.


Some of the key features of AWS Systems Manager (SSM) include:


Parameter Store: SSM Parameter Store allows you to securely store configuration data such as database connection strings, API keys, and environment variables. You can store these parameters hierarchically and encrypt them with AWS Key Management Service (KMS) for added security.

Run Command: SSM Run Command allows you to remotely execute commands on your EC2 instances, on-premises servers, or virtual machines (VMs) running in your hybrid environment. This enables you to perform tasks such as patch management, software installations, and configuration updates across your fleet of instances.

Session Manager: SSM Session Manager provides secure, auditable remote access to your instances without the need for bastion hosts or open SSH ports. You can initiate interactive sessions to troubleshoot and diagnose issues on your instances directly from the AWS Management Console or CLI.

Automation: SSM Automation allows you to automate common maintenance and deployment tasks by defining workflows using pre-built or custom automation documents. You can execute these automation workflows on demand or schedule them to run at specified intervals.

State Manager: SSM State Manager allows you to define and enforce desired configurations on your instances using State Manager associations. You can specify configurations for operating system settings, applications, and other parameters, and SSM will automatically apply and maintain the desired state on your instances.

Inventory: SSM Inventory provides visibility into the configuration and software inventory of your instances. It automatically collects metadata about your instances, including installed applications, network configurations, and file system details, which you can query and filter using AWS Config or other tools.

Overall, AWS Systems Manager (SSM) is a powerful suite of tools for managing and automating operational tasks on AWS, helping you maintain the health, security, and compliance of your infrastructure with ease.



8)sqs vs sns vs event bridge please explain in easy way?

Ans:

Certainly! Let's break down SQS, SNS, and EventBridge in an easy-to-understand way:


SQS (Simple Queue Service):

Imagine you're at a fast-food restaurant, and there's a queue of customers waiting to place their orders. Each customer joins the line and waits their turn to place an order.

SQS works similarly. It's like a queue where messages (orders) are sent and stored temporarily until they're processed by a consumer (worker).

Messages in SQS are processed one by one in the order they were received.

Use SQS when you need to decouple the components of your application, handle bursts of incoming messages, or ensure reliable message delivery.

SNS (Simple Notification Service):

Picture a loudspeaker system in a busy office building. When there's important news or announcements, the loudspeaker broadcasts the message to everyone who's subscribed to listen.

SNS works like this loudspeaker system. It's a pub/sub (publish/subscribe) messaging service that delivers messages to multiple subscribers (endpoints) simultaneously.

Messages in SNS are published to topics, and subscribers can receive these messages in real-time.

Use SNS when you need to broadcast messages to multiple recipients, send notifications, or trigger actions based on events.

EventBridge:

Think of EventBridge as a central hub or a control tower at an airport. It receives information about events happening across various systems and applications, then routes and processes these events accordingly.

EventBridge (formerly known as CloudWatch Events) is a serverless event bus that simplifies event-driven architectures.

It enables you to capture events from AWS services, custom applications, or third-party SaaS applications, and route them to targets like Lambda functions, SNS topics, SQS queues, or even HTTP endpoints.

EventBridge provides event filtering, transformation, and routing capabilities, allowing you to build event-driven workflows and integrations easily.

In summary:


Use SQS for reliable message queuing and processing.

Use SNS for pub/sub messaging and broadcasting messages to multiple subscribers.

Use EventBridge for building event-driven architectures, capturing and routing events across your systems, and integrating with various AWS services and external applications.


9)Lambda default memory and s3:

The total volume of data and number of objects you can store in Amazon S3 are unlimited. Individual Amazon S3 objects can range in size from a minimum of 0 bytes to a maximum of 5 TB. The largest object that can be uploaded in a single PUT is 5 GB. For objects larger than 100 MB, customers should consider using the multipart upload capability.


The default memory allocation for Lambda functions is 128 MB. When you create a new Lambda function, if you don't specify a memory size, it will default to 128 MB.

The maximum memory you can configure for a Lambda function is 10 GB. The memory size also correlates with the vCPUs that are available to your function, meaning higher memory configuration will result in faster computation times.


10)If upload a a file data to s3 in multiple times we need to store track  of it.?
Ans;

  1. S3 Event Notifications: Configure S3 event notifications to trigger a Lambda function or an SNS topic when objects are uploaded to the bucket. Your Lambda function or SNS topic can then process the event, log information about the uploaded file, and store it in a database, log file, or any other persistent storage.

11) What is ref functions and output in serverless?


In the context of the Serverless Framework, Ref is a function used within the framework's configuration files (typically written in YAML or JSON) to reference other resources within the same configuration or even in external services like AWS CloudFormation. Here's a basic breakdown: Ref Function: It allows you to reference a resource defined elsewhere in your configuration. For example, if you have defined an AWS Lambda function named "myFunction", you can reference it using the Ref function within another part of your configuration. Output: Outputs in the Serverless Framework configuration are used to expose certain values or properties of your resources after they have been deployed. These outputs can be useful for integrating with other services or for providing information to users about the deployed resources. Here's a simple example to illustrate how Ref and outputs might be used: yaml Copy code # serverless.yml service: myService provider: name: aws runtime: nodejs14.x functions: myFunction: handler: handler.myFunction resources: Outputs: MyFunctionArn: Value: Ref: myFunction Description: ARN of the MyFunction Lambda function In this example: The myFunction Lambda function is defined under the functions section. The Outputs section specifies an output called MyFunctionArn. The Value of MyFunctionArn uses the Ref function to reference the myFunction Lambda function. After deploying this configuration, you can retrieve the ARN (Amazon Resource Name) of the myFunction Lambda function using the MyFunctionArn output. This is just a basic example, and the usage of Ref and outputs can vary depending on your specific use case and the resources you're working with in your Serverless Framework configuration.


12)CORS vs IPWhitelisting?

Use Case: Serverless API


Imagine you have a serverless API built using AWS Lambda and API Gateway. Your API provides endpoints for retrieving and updating user information.


CORS (Cross-Origin Resource Sharing):Let's say you have a frontend web application hosted on www.example.com, and you want users to be able to access your serverless API from this domain. However, your API, hosted on api.example.com, needs to allow requests from this frontend.

CORS comes into play here. You configure CORS headers on your API Gateway to allow requests from www.example.com. When a user interacts with your frontend and makes a request to your API, the browser checks the CORS headers returned by the API to ensure the request is allowed from www.example.com. If the CORS headers permit it, the browser allows the request to proceed.

IP Whitelisting:Now, let's say you want to restrict access to certain endpoints of your API to only be allowed from your company's office IP addresses. You want to ensure that only requests originating from your office network can access these endpoints, as they handle sensitive operations.

IP Whitelisting is useful here. You configure your API Gateway to whitelist the IP addresses of your company's office network. When a request hits your API, it checks the IP address of the client making the request. If the IP address is on the whitelist, the request is allowed to proceed. Otherwise, it's denied.

In summary, CORS is used to control access to resources from web pages served from different domains in the browser, while IP whitelisting is used to control access to a server or service based on the IP address of the client making the request, regardless of the domain.


13)Clouds Watch:

Ans:

CloudWatch is like a watchdog for your AWS (Amazon Web Services) resources. It helps you monitor and collect data about your applications, systems, and services running on AWS.


Here's how it works:


Monitoring: CloudWatch continuously collects and tracks metrics, which are basically measurements of your resources' performance or behavior. For example, it can track CPU utilization, network traffic, or the number of requests to your website.

Logging: CloudWatch also allows you to store and analyze logs generated by your applications and services. These logs can contain valuable information about what's happening within your system, such as error messages, access logs, or debug information.

Alerting: Now, here's where alarms come into play. With CloudWatch, you can set up alarms to notify you when certain conditions are met. For example, you might want to receive an alert when CPU usage on your server exceeds a certain threshold, or when the number of errors in your application logs increases beyond a certain level.

In simple terms, CloudWatch helps you keep an eye on your AWS resources, collects data to help you understand how they're performing, stores logs for troubleshooting, and alerts you when something needs your attention.


So, think of CloudWatch as your trusty assistant that keeps track of everything happening in your AWS world and taps you on the shoulder when something important happens.



https://dev.to/kevin-uehara/solid-the-simple-way-to-understand-47im







Comments

Popular posts from this blog

Globant part 1

 1)call,apply,bind example? Ans: a. call Method: The call method is used to call a function with a given this value and arguments provided individually. Javascript code: function greet(name) {   console.log(`Hello, ${name}! I am ${this.role}.`); } const person = {   role: 'developer' }; greet.call(person, 'Alice'); // Output: Hello, Alice! I am developer. In this example, call invokes the greet function with person as the this value and passes 'Alice' as an argument. b. apply Method: The apply method is similar to call, but it accepts arguments as an array. Javascript code: function introduce(language1, language2) {   console.log(`I can code in ${language1} and ${language2}. I am ${this.name}.`); } const coder = {   name: 'Bob' }; introduce.apply(coder, ['JavaScript', 'Python']); // Output: I can code in JavaScript and Python. I am Bob. Here, apply is used to invoke introduce with coder as this and an array ['JavaScript', 'Pyt...

Node.js: Extract text from image using Tesseract.

In this article, we will see how to extract text from images using Tesseract . So let's start with this use-case, Suppose you have 300 screenshot images in your mobile which has an email attribute that you need for some reason like growing your network or for email marketing. To get an email from all these images manually into CSV or excel will take a lot of time. So now we will check how to automate this thing. First, you need to install Tesseract OCR( An optical character recognition engine ) pre-built binary package for a particular OS. I have tested it for Windows 10. For Windows 10, you can install  it from here. For other OS you make check  this link. So once you install Tesseract from windows setup, you also need to set path variable probably, 'C:\Program Files\Tesseract-OCR' to access it from any location. Then you need to install textract library from npm. To read the path of these 300 images we can select all images and can rename it to som...

CSS INTERVIEW QUESTIONS SET 2

  You make also like this CSS interview question set 1. Let's begin with set 2, 5)What is the difference between opacity 0 vs display none vs visibility hidden? Property           | occupies space | consumes clicks | +--------------------+----------------+-----------------+ | opacity: 0         |        yes      |        yes       | +--------------------+----------------+-----------------+ | visibility: hidden |        yes       |        no        | +--------------------+----------------+-----------------+ | display: none      |        no       |        no        | When we say it consumes click, that means it also consumes other pointer-events like onmousedown,onmousemove, etc. In e...