Skip to content

Instantly share code, notes, and snippets.

View markilott's full-sized avatar

Mark Ilott markilott

  • 22:31 (UTC +07:00)
View GitHub Profile
@markilott
markilott / aws-sftp-demo.yaml
Last active July 3, 2020 08:19
AWS Transfer CloundFormation Demo
AWSTemplateFormatVersion: '2010-09-09'
Description: >-
AWS Transfer SFTP with EIP and Security Group
You can choose a fully automated and self-contained demo by creating a new VPC.
Or you can select an existing VPC. The VPC must have 2 public subnets with internet access.
There is one manual step in the Console required for an existing VPC after the CloudFormation script-
- Open the VPC Service page
- Go to Endpoints
- Select the new transfer Endpoint
@markilott
markilott / aws-managed-ad-demo.yaml
Created July 5, 2020 04:17
AWS Managed AD Demo
AWSTemplateFormatVersion: "2010-09-09"
Description: >-
Creates-
- a Managed AD, with the domain name you specify
- admin server joined to the domain
- Secrets Manager secret with the AD Admin password
Requires-
- an existing VPC with at least 2 subnets
- EC2 Key Pair in the current region
- Windows Server 2016 AMI ID in the current region
@markilott
markilott / 1.source-account-prep.yaml
Last active January 24, 2021 07:47
CloudFormation to allow CodeCommit event forwarding to CodePipeline in another account. For use with CDK pipelines.
#############################################################
# This template is used to prepare the Shared Services Account so that
# the Pipeline can be triggered by CodeCommit in DEV.
#
# Run this template First
#
#############################################################
Description: Allow CodeCommit Events forwarding from DEV
Resources:
@markilott
markilott / alb-listener.js
Created July 18, 2021 08:48
ALB Listener with restricted inbound
// Https listener
const httpsListener = alb.addListener('https', {
port: 443,
protocol: ApplicationProtocol.HTTPS,
certificates: [certificate],
open: false, // Prevent CDK from adding an allow all inbound rule to the security group
});
@markilott
markilott / alb-target-group-fargate.js
Created July 18, 2021 08:53
ALB Target Group for Fargate Services
// Target Group. Fargate stack will add services to this group
new ApplicationTargetGroup(this, 'fargateTargetGroup', {
vpc,
port,
// IP target type is required for Fargate services - it must be specified here if attaching services in other stacks
targetType: TargetType.IP,
});
@markilott
markilott / start-stop-fargate-task.js
Created July 18, 2021 09:09
Set desired task count to start/stop Fargate tasks
const AWS = require('aws-sdk');
const ecs = new AWS.ECS();
// Update the desired task count
await ecs.updateService({
service,
cluster,
desiredCount: 0, // 0 to stop, 1 (or more) to start
}).promise();
@markilott
markilott / scheduler-fnc-cdk.js
Created July 18, 2021 09:20
CDK - Lambda Function to start/stop ECS services
// In the Scheduler Stack ===========================================
// Lambda Function to start/stop tasks
const ecsScheduleFnc = new Function(this, 'ecsScheduleFnc', {
description: 'Lambda ECS Service Mgt Function',
functionName: 'ecsScheduleFnc',
runtime: Runtime.NODEJS_14_X,
handler: 'index.handler',
timeout: Duration.seconds(5),
code: Code.fromAsset(`${__dirname}/lambda/manage-task`),
});
@markilott
markilott / ses-email-test.sh
Created July 25, 2021 06:59
Test SES Email via CLI
aws sesv2 send-email \
--from-email-address "no-reply@mydomain.com" \
--destination "ToAddresses=me@myotherdomain.com" \
--configuration-set-name "myConfigSet" \
--content "Simple={Subject={Data=Hello World,Charset=utf8},Body={Text={Data=Hi from SES,Charset=utf8},Html={Data=<p>Hi from SES<p>,Charset=utf8}}}"
@markilott
markilott / cdk-ses-identity-policy.js
Created July 25, 2021 07:22
CDK Custom Resource Policy for SES Email Identity
// Creating custom policy for CustomResource due to CDK bug (uses email: instead of ses: when creating actions)
const sesPolicy = new PolicyStatement({
actions: [
'ses:CreateConfigurationSet',
'ses:DeleteConfigurationSet',
'ses:CreateConfigurationSetEventDestination',
'ses:DeleteConfigurationSetEventDestination',
'ses:CreateEmailIdentity',
'ses:DeleteEmailIdentity',
],
@markilott
markilott / cdk-ses-domain-identity.js
Created July 25, 2021 07:36
CDK Custom Resource - SES Domain Identity
// Add and verify Domain using DKIM
const domainIdentity = new AwsCustomResource(this, 'domainIdentity', {
onUpdate: {
service: 'SESV2',
action: 'createEmailIdentity',
parameters: {
EmailIdentity: zoneName,
ConfigurationSetName, // Will set the default Configuration Set for the domain
},
physicalResourceId: {},