Skip to content

Instantly share code, notes, and snippets.

View alexpulver's full-sized avatar

Alex Pulver alexpulver

View GitHub Profile
@alexpulver
alexpulver / README.md
Created May 19, 2023 05:41
ADF short stories

Legend

> - stack name
>> - stack resource name

Story 1

Needed to build identity provider. Decided to use Cognito for all functionality. Created identity provider app with a single identity provider component.

@alexpulver
alexpulver / README.md
Last active September 12, 2022 07:29
Parallel deployment using AWS CDK Toolkit --concurrency

Instructions

git clone https://github.com/alexpulver/aws-cdk-project-structure-python-basic.git
cd aws-cdk-project-structure-python-basic

# Deploy both stacks to default AWS account and Region
sed -i '' 's/"111111111111"/os.environ["CDK_DEFAULT_ACCOUNT"]/' app.py
sed -i '' 's/"eu-west-1"/os.environ["CDK_DEFAULT_REGION"]/' app.py

# Install project dependencies (including local installation of AWS CDK Toolkit)
@alexpulver
alexpulver / README.md
Created March 6, 2022 12:08
CDK Pipelines ECR source attribute example

Running the example

python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
cdk synth --app "python app.py"
@alexpulver
alexpulver / toolchain.py
Created September 4, 2021 05:02
Add CodeBuild project as the only action in a CDK Pipelines pipeline stage
pipeline = pipelines.CodePipeline(...)
kubectl = pipelines.ShellStep(
"Kubectl",
commands=["kubectl apply -f deployment.yml"],
)
pipeline.add_wave("Kubernetes", post=[kubectl])
@alexpulver
alexpulver / toolchain.py
Last active November 12, 2021 07:12
Enable CodeBuild cache for CDK Pipelines synth step
synth_codebuild_step = pipelines.CodeBuildStep(...)
codepipeline = pipelines.CodePipeline(
self,
"CodePipeline",
synth=synth_codebuild_step,
)
# That should be called at the end of the pipeline definition, because the pipeline can't be changed afterwards
codepipeline.build_pipeline()
synth_cfn_project: codebuild.CfnProject = codepipeline.synth_project.node.default_child
synth_cfn_project.cache = codebuild.CfnProject.ProjectCacheProperty(type="LOCAL", modes=["LOCAL_SOURCE_CACHE"])
@alexpulver
alexpulver / commands.txt
Created December 30, 2018 05:40
Example of using AWS CLI to configure and launch Amazon EC2 Fleet
aws ec2 create-fleet --cli-input-json file://config.json
aws ec2 describe-fleets
aws ec2 describe-fleet-instances --fleet-id fleet-3110fe2c-6589-4a42-8f75-12c1746e50a9
aws ec2 delete-fleets --fleet-ids fleet-3110fe2c-6589-4a42-8f75-12c1746e50a9 --terminate-instances
@alexpulver
alexpulver / s3_select_records.py
Created December 23, 2018 09:56
Iterating over records in Amazon S3 Select result
import boto3
client = boto3.client('s3')
response = client.select_object_content(
Bucket='string',
Key='string',
SSECustomerAlgorithm='string',
SSECustomerKey='string',
Expression='string',
@alexpulver
alexpulver / README.md
Created December 17, 2018 08:20
AWS Chalice - Continuous Deployment (CD)

Deploying the demo

Global configuration

export AWS_PROFILE=NAME
export AWS_DEFAULT_REGION=REGION
git config --global credential.helper '!aws --profile '$AWS_PROFILE' codecommit credential-helper $@'
git config --global credential.UseHttpPath true
@alexpulver
alexpulver / README.md
Last active December 4, 2018 20:29
Amazon EC2 self-service user permissions

Use case

Below is an example for IAM policy and commands to allow IAM users (could be federated users as well) create EC2 instances in self-service manner, while enforcing the following:

  • The IAM user must provide "owner" tag with their currently logged-in IAM username as value. Otherwise they won't be able to create the instance.
  • Each IAM user can start, stop and terminate their own instances only. The enforcement is based on currently logged-in IAM username.
  • The IAM user can only apply "owner" tag when creating the instance and cannot modify any tag later.

Documentation

Supported Resource-Level Permissions for Amazon EC2 API Actions