• Skip to main content

Uly.me

cloud engineer

  • Home
  • About
  • Archives

template

EBS volume stuck in CloudFormation

November 12, 2020

When running CloudFormation, all the resources are being created with no problem. However it seems to be getting stuck at creating or mounting a volume. The CloudFormation fails and initiates a rollback. This is the error I am getting.

Volume attachment between volume-id vol-xxxxxxxx and instance-id i-xxxxxxx at device /dev/xvda is attaching

Volume attachment between volume-id vol-xxxxxxxx and instance-id i-xxxxxxx at device /dev/xvda is attaching

This turned out to be a conflict on HVM EC2 instances because /dev/sda1 is being remapped to /dev/xvda. My second drive is also mapped to /dev/xvda. The fix was to simply to map it slightly different to avoid mapping conflict.

Here’s the original mapping.

Boot:   /dev/xvda
Device: /dev/xvda
Device: /dev/xvdb

Boot: /dev/xvda Device: /dev/xvda Device: /dev/xvdb

Here’s the fix.

Boot:   /dev/xvda
Device: /dev/xvdb
Device: /dev/xvdc

Boot: /dev/xvda Device: /dev/xvdb Device: /dev/xvdc

Filed Under: Cloud Tagged With: aws, cloudformation, conflict, drive, mapping, template, volume

WordPress Numeric Pagination

September 8, 2019

Here’s how to add numeric pagination on your WordPress pages.

Add this code to functions.php.

function pagination($pages = '', $range = 4) {
  $showitems = ($range * 2)+1;
  global $paged;
  if(empty($paged)) $paged = 1;
  if($pages == '') {
    global $wp_query;
    $pages = $wp_query->max_num_pages;
    if(!$pages) {
      $pages = 1;
    }
  }
  if(1 != $pages) {
    echo '<p><div class="pagination"><span>Page' . $paged . ' of  ' . $pages . '</span>   ';
    if($paged > 2 && $paged > $range+1 && $showitems < $pages) echo '<a href="' . get_pagenum_link(1) . '"><< First</a>';
    if($paged > 1 && $showitems < $pages) echo '<a href="'.get_pagenum_link($paged - 1).'">< Previous</a>';
    for ($i=1; $i <= $pages; $i++) {
      if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems )) {
        echo ($paged == $i)? '<span class="current">' . $i . '</span>' : '<a href="' . get_pagenum_link($i) . '"class="inactive">' . $i . '</a>';
      }
    }
    if ($paged < $pages && $showitems < $pages) echo '<a href="' . get_pagenum_link($paged + 1) . '">Next ></a>';
    if ($paged < $pages-1 && $paged+$range-1 < $pages && $showitems < $pages) echo '<a href="' . get_pagenum_link($pages) . '">Last >></a>';
    echo '</div></p>';
  }
}

function pagination($pages = '', $range = 4) { $showitems = ($range * 2)+1; global $paged; if(empty($paged)) $paged = 1; if($pages == '') { global $wp_query; $pages = $wp_query->max_num_pages; if(!$pages) { $pages = 1; } } if(1 != $pages) { echo '<p><div class="pagination"><span>Page' . $paged . ' of ' . $pages . '</span> '; if($paged > 2 && $paged > $range+1 && $showitems < $pages) echo '<a href="' . get_pagenum_link(1) . '"><< First</a>'; if($paged > 1 && $showitems < $pages) echo '<a href="'.get_pagenum_link($paged - 1).'">< Previous</a>'; for ($i=1; $i <= $pages; $i++) { if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems )) { echo ($paged == $i)? '<span class="current">' . $i . '</span>' : '<a href="' . get_pagenum_link($i) . '"class="inactive">' . $i . '</a>'; } } if ($paged < $pages && $showitems < $pages) echo '<a href="' . get_pagenum_link($paged + 1) . '">Next ></a>'; if ($paged < $pages-1 && $paged+$range-1 < $pages && $showitems < $pages) echo '<a href="' . get_pagenum_link($pages) . '">Last >></a>'; echo '</div></p>'; } }

To display, comment out ‘the_post_navigation’ function and add the ‘pagination’ function instead in your template files.

//the_posts_navigation();
pagination();

//the_posts_navigation(); pagination();

Code courtesy of webdesignsun.

Filed Under: WP Tagged With: function, numeric, pagination, php, template, wordpress

EFS CloudFormation

June 9, 2019

Here’s a simple EFS CloudFormation template with a one mount target.

{
	"AWSTemplateFormatVersion": "2010-09-09",
	"Description": "EFS example setup",
	"Parameters": {
		"VPC": {
			"Description": "VPC ID",
			"Type": "AWS::EC2::VPC::Id"
		},
		"Subnet": {			
			"Description": "Subnet ID",
			"Type": "AWS::EC2::Subnet::Id"
		},
		"EC2SecurityGroup": {
			"Description": "Security Group for EC2 instance",
			"Type": "AWS::EC2::SecurityGroup::Id"
		}	
	},
	"Resources": {
		"EFSFileSystem": {
			"Type" : "AWS::EFS::FileSystem",
			"Properties" : {
				"FileSystemTags" : [
					{"Key" : "Name", "Value" : {"Ref": "AWS::StackName"}}
				]
			}
		},
		"EFSMountTarget": {
			"Type": "AWS::EFS::MountTarget",
			"Properties": {
				"FileSystemId": {"Ref": "EFSFileSystem"},
				"SubnetId": { "Ref": "Subnet" },
				"SecurityGroups": [{"Ref": "EFSSecurityGroup"}]        
			}
		},
		"EFSSecurityGroup": {
			"Type": "AWS::EC2::SecurityGroup",
			"Properties": {
				"GroupDescription": "Allowing access to EFS",
				"VpcId": {"Ref": "VPC"},
				"SecurityGroupIngress": [{
					"IpProtocol": "tcp",
					"FromPort": 2049,
					"ToPort": 2049,
					"SourceSecurityGroupId": {"Ref": "EC2SecurityGroup"}
				}]
			}
		}				
	}
}

{ "AWSTemplateFormatVersion": "2010-09-09", "Description": "EFS example setup", "Parameters": { "VPC": { "Description": "VPC ID", "Type": "AWS::EC2::VPC::Id" }, "Subnet": { "Description": "Subnet ID", "Type": "AWS::EC2::Subnet::Id" }, "EC2SecurityGroup": { "Description": "Security Group for EC2 instance", "Type": "AWS::EC2::SecurityGroup::Id" } }, "Resources": { "EFSFileSystem": { "Type" : "AWS::EFS::FileSystem", "Properties" : { "FileSystemTags" : [ {"Key" : "Name", "Value" : {"Ref": "AWS::StackName"}} ] } }, "EFSMountTarget": { "Type": "AWS::EFS::MountTarget", "Properties": { "FileSystemId": {"Ref": "EFSFileSystem"}, "SubnetId": { "Ref": "Subnet" }, "SecurityGroups": [{"Ref": "EFSSecurityGroup"}] } }, "EFSSecurityGroup": { "Type": "AWS::EC2::SecurityGroup", "Properties": { "GroupDescription": "Allowing access to EFS", "VpcId": {"Ref": "VPC"}, "SecurityGroupIngress": [{ "IpProtocol": "tcp", "FromPort": 2049, "ToPort": 2049, "SourceSecurityGroupId": {"Ref": "EC2SecurityGroup"} }] } } } }

Filed Under: Cloud Tagged With: aws, cloudformation, efs, mount target, template

  • Home
  • About
  • Archives

Copyright © 2023