Skip to content

Instantly share code, notes, and snippets.

View CFML_LAMBDA.sh
sudo yum install -y https://corretto.aws/downloads/latest/amazon-corretto-8-x64-linux-jdk.rpm
wget https://services.gradle.org/distributions/gradle-6.5-bin.zip -P /tmp
sudo unzip -d /opt/gradle /tmp/gradle-6.5-bin.zip
export GRADLE_HOME=/opt/gradle/gradle-6.5
export PATH=${GRADLE_HOME}/bin:${PATH}
cat >> ~/.bash_profile <<TXT
View sample.php
<?php
function index($event) {
$invokedBy = $event['user'];
$output = " world!, function invoked by " . $invokedBy;
return('Hello' . $output);
}
View Deploy-php.sh
# Update packages and install needed compilation dependencies
sudo yum update -y
sudo yum install autoconf bison gcc gcc-c++ libcurl-devel libxml2-devel -y
# Compile OpenSSL v1.0.1 from source, as Amazon Linux uses a newer version than the Lambda Execution Environment, which
# would otherwise produce an incompatible binary.
curl -sL http://www.openssl.org/source/openssl-1.0.1k.tar.gz | tar -xvz
cd openssl-1.0.1k
./config && make && sudo make install
cd ~
View code.js
// Static Code into Bucket.
const deployment = new s3Deployment.BucketDeployment(
this,
'deployStaticWebsite',
{
sources: [s3Deployment.Source.asset('./program/static')],
destinationBucket: publicAssets,
}
);
View env.js
#!/usr/bin/env node
import 'source-map-support/register';
import * as cdk from '@aws-cdk/core';
import { AwsCdkS3Stack } from '../lib/aws-cdk-s3-stack';
const app = new cdk.App();
new AwsCdkS3Stack(app, 'AwsCdkS3Stack', {
env: {
account: process.env.CDK_DEFAULT_ACCOUNT,
region: process.env.CDK_DEFAULT_REGION
View fullCode.js
import * as cdk from '@aws-cdk/core';
import * as s3 from '@aws-cdk/aws-s3';
import * as s3Deployment from '@aws-cdk/aws-s3-deployment';
import * as route53 from '@aws-cdk/aws-route53';
export class AwsCdkS3Stack extends cdk.Stack {
constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
// Create the public S3 bucket
View setup.js
//Add the Subdomain to Route53
const cName = new route53.CnameRecord(this, 'test.baseZone', {
zone: zone,
recordName: 'example',
domainName: publicAssets.bucketWebsiteDomainName
});
View setup.js
//Lookup the zone based on domain name
const zone = route53.HostedZone.fromLookup(this, 'baseZone', {
domainName: 'url2qr.me'
});
View setup.js
//Create the public S3 bucket
const publicAssets = new s3.Bucket(this, 'example-qr', {
bucketName: 'example.{you-domain}',
publicReadAccess: true,
removalPolicy: cdk.RemovalPolicy.DESTROY,
websiteIndexDocument: 'index.html',
});
View setup.sh
# Create a folder for the Program, this is my convention the program may have more parts
# for now it's just static so create just those folders
mkdir -p Program/static
# Populate the index.html file with some content
echo "S3 Hosting with CDK" > Program/static/index.html