@daxinator22/aws v2.0.0
Polfwack AWS SDK
Welcome to the Polfwack AWS SDK. The SDK was made as an alternative to using the traditional AWS SDK to interact with services.
What's the differene?
The creator of the Polfwack AWS SDK found 2 problems with the AWS SDK. The first is the API calls are usually meant for batch operations. Batch operations are not good and often overkill for what a basic AWS user would want to do with the SDK. The second is the AWS is modular and not object oriented. The latter isn't necessarily a problem, but an object-oriented approach would be more suited to working with individual services or instances. The Polfwack AWS SDK seeks to solve these 2 problems with the AWS SDK.
Credentials
In order to use the Polfwack AWS SDK, the user must have an AWS account with programmatic access. The user must put these credentials in a file named credentials.json
in the top level project directory. The SDK looks specifically for this file, and will fail if this file is not included. It is best practice to not commit these credentials to any public GIT repository. Please make sure to exclude the credentials.json
file in the project's .gitignore
file.
Importable Objects
Every importable object inherits from the base Service
object. There are 2 ways to instantiate service objects: using the regular constructor or using the static get
method. The regular constructor is used for creating new AWS services that don't exist yet in AWS. They are meant to be blank services that users can use to create new services. See the following usage example:
import { EC2 } from "@daxinator22/aws/aws.js";
// Creating blank EC2 instance
const newInstance = new EC2();
// Configure instance before launching
newInstance.update(
{
InstanceType: "t2.micro"
}
);
The other way to instantiate service objects is using the static get
method. The get
method is meant to retreive an AWS service that already exists. Each get
method for each service uses a different value (i.e. id, name, ARN) to retireve the service from AWS. See the specific object for more information on which value is used in the get
method. Here is an example of how to use the get
method to retreive an active service from AWS:
import { EC2 } from "@daxinator22/aws/aws.js";
// Get active service from AWS
const instance = await EC2.get("INSTANCE_ID");
// Do something with the instance
console.log(instance.describe());
Methods
constructor()
: Used for creating new AWS servicesget()
: Used for retreiving active AWS servicesdescribe()
: Returns information about the service. The structure of this object mirrors the AWS SDKdescribe
function for whatever service the user is describing.update(config)
: Takes an object of values to update in the service config. Generally, using the methods for the individual services will update the config so the user doesn't have to do this manually, but for creating new objects the user can use this method to configure the service.refresh()
: Refreshes information about the service. The user can call this manually, but this method is generally called after every action performed to each service.
Certificate
The Certificate
object allows users to create new SSL certificates in AWS ACM or modify existing ones.
Usage
import { Certificate } from "@daxinator22/aws/aws.js";
const certificate = await Certificate.get("CERTIFICATE_ARN");
Methods
constructor()
: Used to create a new SSL certificate.get(certificateArn)
: Used to retreive an existing SSL certificate. Requires a certificate ARN.createCertificate()
: Creates an new SSL certificate in AWS ACM with the desired domain names. TheDomainName
field must be defined in order to create a new certificate. TheSubjectAlternativeNames
can be used to specify other domain names to add the certificate. The validation method is set to DNS by default, which means the user must have access to the DNS of the all of the domain names on the certificate. If these domains are hosted in AWS Route 53, then AWS will handle the domain validation for the certificate.deleteCertificate()
: Deletes an exisint SSL certificate in AWS ACM.waitForValidation()
: Waits for SSL validation to complete.
DNS Record
The DNSRecord
is used to create and modify DNS records in AWS Route 53. This class is a data class and does not extend the Service
object. In order to create or modify records, the user must use a Route53
object.
Usage
import { DNSRecord } from "@daxinator22/aws/aws.js";
const record = new DNSRecord("RECORD_NAME");
Attributes
name
: The DNS record name.type
: The DNS record type.aliasTarget
: The alias target information. Currently, DNS records can only alias to other AWS services. TheHostedZoneId
andDNSName
must be defined.
Method
constructor(recordName)
: Creates a newDNSRecord
instance. Initializestype
toA
.setAliasTarget(dnsName, hostedZoneId)
: Sets the instance'saliasTarget
to the specified values.
EC2
The EC2
object allows users to create new EC2 instances or modify existing ones.
Usage
import { EC2 } from "@daxinator22/aws/aws.js";
const instance = await EC2.get("INSTANCE_ID");
Methods
constructor()
: Used to create a new EC2 instance.get(instanceId)
: Used to retreive an existing EC2 instance. Needs an EC2 instance id.launchInstance()
: Launches a new instance with the specified configuration. RequiresImageId
andInstanceType
to be defined in the configuration.launchInstanceFromTemplate(templateId)
: Launches a new instance from the specified launch template id.waitForLaunch()
: Waits for instance state to beready
.terminateInstance()
: Terminates instance.waitForTerminate()
: Waits for instance state to beterminated
.setInstanceName(name)
: UpdatesName
tag for instance to the desired name. Will create a new tag if theName
tag does not exist.addToSecurityGroup(securityGroupId)
: Adds the instance to the given security group.
Elastic Beanstalk
The ElasticBeanstalk
object allows users to create new Elastic Beanstalk environments and modify existing ones.
Usage
import { ElasticBeanstalk } from "@daxinator22/aws/aws.js";
const elasticBeanstalkEnv = await ElasticBeanstalk.get(ELASTIC_BEANSTALK_ENVIRONMENT_ID);
Methods
constructor()
: Used to create a new Elastic Beanstalk environment.get(environmentId)
: Used to retreive an existing Elastic Beanstalk environment.getElasticBeanstalkResources()
: Gets information about the environment resources.getEnvironmentConfiguration()
: Gets information about the environment configuration.updateDeploymentVersion(versionName)
: Updates the environment to the specified version. The version must already exist in the application. The version name provided to the method must match the version label in the application versions.updateEnvironmentSSL(certificateArn)
: Updates the environment's load balancer to use the specified SSL certificate from ACM. This was meant to be used for an environment with either a Classic or Application Load Balancer. This is because it only changes the SSL certificate for the port 443 listener. Network Load Balancers are not supported for this function.waitForUpdate()
: Waits for environment to update.launchEnvironment()
: Launches a new Elastic Beanstalk environment with the specified configuration. TheApplicationName
,EnvironmentName
andPlatformArn
must be defined in the configuration for this funciton to work.waitForLaunch()
: Waits for environment to launch.terminateEnvironment()
: Terminates the environment.waitForTerminate()
: Waits for environment to terminate.getInstanceIds()
: Returns a list of EC2 instance ids that are associated with the environment.restartAppServers()
: Performs therestartAppServers
function on the environment. Please note this may not reboot the EC2 instance depending on the platform.
Elastic Load Balancer
The ElasticLoadBalancer
object allows users to modify existing Elastic Load Balancers.
Usage
import { ElasticLoadBalancer } from "@daxinator22/aws/aws.js";
const loadBalancer = await ElasticLoadBalancer("LOAD_BALANCER_NAME");
Methods
get(loadBalancerName)
: Used to retreive an existing Elastic Load Balancer.setSSLCertificate(certificateArn)
: Sets the SSL certificate on the port 443 for the load balancer. Requires an AWS ACM certificate ARN.getListeners()
: Returns a list of listeners on the load balancer.getAttributes()
: Returns a list of attributes on the load balancer.enableLogging(s3BucketName, prefix)
: Enables logging on the load balancer. Requires and S3 bucket name and a prefix of the destination folder for the logs. The prefix can be an empty string if the user desires the logs to be in the top level of the S3 bucket. Note this method does not modify the permissions of the S3 bucket. The user must ensure that the load balancer can access the bucket before using this method.disableLogging()
: Disables logging on the load balancer.
RDS
The RDS
object is used to modify existing RDS instances.
Usage
import { RDS } from "@daxinator22/aws/aws.js";
const instance = await RDS.get("RDS_IDENTIFIER");
Methods
get(rdsIdentifier)
: Used to retreive an existing RDS instance. Requires an RDS unique identifier.
Route 53
The Route53
object is used to modify exisint Route 53 hosted zones.
Usage
import { Route53 } from "@daxinator22/aws/aws.js";
const hostedZone = await Route53.get("ROUTE53_HOSTED_ZONE_ID");
Methods
get(hostedZoneId)
: Used to retreive an exisitng Route 53 hosted zone.updateRecord(dnsRecord)
: Updates a specific record. Will create the record if one doesn't exist. Requires a DNSRecord object.getRecord(recordName, recordType)
: Gets the record of the specified record name and type from the hosted zone. The default type isA
.
S3
The S3
object allows users to retreive objects from an S3 bucket.
Usage
import { S3 } from "@daxinator22/aws/aws.js";
const bucket = await S3.get("S3_BUCKET_NAME");
Methods
get(bucketName)
: Used to retreive an S3 bucket. Requires the S3 bucket name.downloadObject(objectKey, downloadPath)
: Downloads an object from the bucket. Requires the object's key and path where the user wishes to store the download file.
Security Group
The SecurityGroup
object allows users to modify existing security groups.
Usage
import { SecurityGroup } from "@daxinator22/aws/aws.js";
const securityGroup = await SecurityGroup("SECURITY_GROUP_ID");
Methods
get(securityGroupId)
: Used to retrieve an existing security group. Requires a security group id.listRules()
: Retreives a list of inbound and outbound rules for the security group.
Services
The Services
object is used for getting information about all of the active services. The user can't modify servies from here and should use the service objects to perform those operations. The user can use this object to search for services with a specific name or configuration. This object does not inherit from the Service
object.
Usage
import { Services } from "@daxinator22/aws/aws.js";
// Create Services object
const services = new Services();
// List all EC2 instances
const instances = await services.listEC2Instances();
Methods
constructor()
: Creates aServices
object.listEC2Instances()
: Lists all EC2 instances.listEC2LaunchTemplates()
: Lists all launch templates available to EC2 instances.getEC2LaunchTemplateId(templateName)
: Returns a launch template id. Requires a launch template name.listS3Buckets()
: Lists all S3 buckets.listElasticBeanstalkEnvironments()
: Lists all Elastic Beanstalk environmentsgetElasticBeanstalkEnvironmentId(environmentName)
: Returns an Elastic Beanstalk environment id. Requries an Elastic Beanstalk environment name.listRoute53HostedZones()
: Lists all Route 53 hosted zones.getRoute53HostedZoneId(hostedZoneName)
: Returns a Route 53 hosted zone id. Requires a Route 53 hosted zone name.listSSLCertificates()
: Lists all ACM SSL certificates.getCertificateArn(certificateName)
: Returns an ACM certificate ARN. Requires the top-level domain name of the certificate.listLoadBalancers()
: Lists all Elastic Load Balancers.getLoadBalancerArn(loadBalancerName)
: Return an Elastic Load Balancer ARN. Requires an Elastic Load Balancer name.listSecurityGroups()
: Lists all security groups`getSecurityGroupId(securityGroupName)
: Returns a security group id. Requires a security group name.listRDSInstances()
: Lists all RDS instances.