How to Get Account Number from AWS Lambda

If you need to get the current Account Number, or Account ID from within a Lambda execution, then you can access invoked_function_arn from the context and return the associated value as follows: aws_account_id = context.invoked_function_arn.split(":")[4]

January 24, 2023 · 1 min · 35 words · Andrew

Summary of the Frequently Used AWS STS API calls

AssumeRole – is useful for allowing existing IAM users to access AWS resources that they don’t already have access to. For example, the user might need access to resources in another AWS account. It is also useful as a means to temporarily gain privileged access—for example, to provide multi-factor authentication (MFA). You must call this API using existing IAM user credentials. AssumeRoleWithWebIdentity – returns a set of temporary security credentials for federated users who are authenticated through a public identity provider....

January 19, 2023 · 2 min · 289 words · Andrew

Understanding Locking and Conditional Writes in AWS DynamoDB

Optimistic locking is a strategy to ensure that the client-side item that you are updating (or deleting) is the same as the item in DynamoDB. Optimistic concurrency depends on checking a value upon save to ensure that it has not changed. If you use this strategy, then your database writes are protected from being overwritten by the writes of others — and vice-versa. By default, the DynamoDB write operations (PutItem, UpdateItem, DeleteItem) are unconditional: each of these operations will overwrite an existing item that has the specified primary key....

January 18, 2023 · 2 min · 258 words · Andrew

AWS CodeDeploy Deployment Type Options

CodeDeploy provides two (2) deployment type options: Option 1 – In-place Deployment In-place deployment: The application on each instance in the deployment group is stopped, the latest application revision is installed, and the new version of the application is started and validated. You can use a load balancer so that each instance is deregistered during its deployment and then restored to service after the deployment is complete. Only deployments that use the EC2/On-Premises compute platform can use in-place deployments....

January 17, 2023 · 2 min · 364 words · Andrew

Defining Amazon ECS Task Placement Strategies

Amazon ECS supports the following task placement strategies: binpack – Place tasks based on the least available amount of CPU or memory. This minimizes the number of instances in use. random – Place tasks randomly. spread – Place tasks evenly based on the specified value. Accepted values are attribute key-value pairs, instanceId, or host.

January 16, 2023 · 1 min · 54 words · Andrew

Deployment methods in AWS Elastic Beanstalk

– All at once – Deploy the new version to all instances simultaneously. All instances in your environment are out of service for a short time while the deployment occurs. – Rolling – Deploy the new version in batches. Each batch is taken out of service during the deployment phase, reducing your environment’s capacity by the number of instances in a batch. – Rolling with additional batch – Deploy the new version in batches, but first launch a new batch of instances to ensure full capacity during the deployment process....

January 15, 2023 · 2 min · 226 words · Andrew

How to update NTP to sync clock on Linux

If you need to sync the clock on Linux using the central NTP clock service, you can do the following: sudo service ntp stop sudo ntpd -gq sudo service ntp start The -gg flags do the following: Tell g flag tells the NTP Daemon to correct the time regardless of the offset The q flag tells it to exit immediately after setting the time

January 4, 2023 · 1 min · 64 words · Andrew

How to Find IP Address Ranges used by Amazon S3

You can query the ip-ranges Amazon AWS URL, and parse the results through jq as follows: Generic S3 IP Ranges Query: curl -s | jq -r '.prefixes[] | select(.service=="S3")' Response: { "ip_prefix": "", "region": "ap-northeast-2", "service": "S3", "network_border_group": "ap-northeast-2" } { "ip_prefix": "", "region": "eu-central-1", "service": "S3", <truncated> Region Specific S3 IP Ranges Query: curl -s | jq -r '.prefixes[] | select(.region=="eu-west-1") | select(.service=="S3") | .ip_prefix' Response: 3....

December 13, 2022 · 1 min · 77 words · Andrew

How to Find the nth Reverse Number in Java

The challenge Reverse Number is a number which is the same when reversed. For example, the first 20 Reverse Numbers are: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 22, 33, 44, 55, 66, 77, 88, 99, 101 Task You need to return the nth reverse number. (Assume that reverse numbers start from 0 as shown in the example.) Notes 1 < n <= 100000000000 The solution in Java Option 1:...

December 12, 2022 · 2 min · 263 words · Andrew

How to Find the Sum of Intervals in Java

The challenge Write a function called sumIntervals/sum_intervals() that accepts an array of intervals, and returns the sum of all the interval lengths. Overlapping intervals should only be counted once. Intervals Intervals are represented by a pair of integers in the form of an array. The first value of the interval will always be less than the second value. Interval example: [1, 5] is an interval from 1 to 5. The length of this interval is 4....

December 11, 2022 · 3 min · 601 words · Andrew