Skip to content

Instantly share code, notes, and snippets.

@delitescere
Last active June 27, 2021 04:40
Show Gist options
  • Save delitescere/366503e09df91820e015aa583e496a24 to your computer and use it in GitHub Desktop.
Save delitescere/366503e09df91820e015aa583e496a24 to your computer and use it in GitHub Desktop.
Pulumi `local` stack for using with localstack https://localstack.cloud
#!/bin/sh -e
PULUMI_STACK=local
STACK_CONFIG_FILE=Pulumi.${PULUMI_STACK}.yaml
LOCALSTACK_ENDPOINT=http://localhost:4566
pulumi stack init ${PULUMI_STACK}
[ -e ${STACK_CONFIG_FILE} ] && printf "\e[0;31merror:\e[0m stack config file '${STACK_CONFIG_FILE}' already exists\n" && exit 1
cat > ${STACK_CONFIG_FILE} <<_END_
config:
aws:accessKey: test
aws:endpoints:
- acm: ${LOCALSTACK_ENDPOINT}
amplify: ${LOCALSTACK_ENDPOINT}
apigateway: ${LOCALSTACK_ENDPOINT}
applicationautoscaling: ${LOCALSTACK_ENDPOINT}
appsync: ${LOCALSTACK_ENDPOINT}
athena: ${LOCALSTACK_ENDPOINT}
autoscaling: ${LOCALSTACK_ENDPOINT}
batch: ${LOCALSTACK_ENDPOINT}
cloudformation: ${LOCALSTACK_ENDPOINT}
cloudfront: ${LOCALSTACK_ENDPOINT}
cloudsearch: ${LOCALSTACK_ENDPOINT}
cloudtrail: ${LOCALSTACK_ENDPOINT}
cloudwatch: ${LOCALSTACK_ENDPOINT}
cloudwatchevents: ${LOCALSTACK_ENDPOINT}
cloudwatchlogs: ${LOCALSTACK_ENDPOINT}
codecommit: ${LOCALSTACK_ENDPOINT}
cognitoidentity: ${LOCALSTACK_ENDPOINT}
cognitoidp: ${LOCALSTACK_ENDPOINT}
docdb: ${LOCALSTACK_ENDPOINT}
dynamodb: ${LOCALSTACK_ENDPOINT}
ec2: ${LOCALSTACK_ENDPOINT}
ecr: ${LOCALSTACK_ENDPOINT}
ecs: ${LOCALSTACK_ENDPOINT}
eks: ${LOCALSTACK_ENDPOINT}
elasticache: ${LOCALSTACK_ENDPOINT}
elasticbeanstalk: ${LOCALSTACK_ENDPOINT}
elb: ${LOCALSTACK_ENDPOINT}
emr: ${LOCALSTACK_ENDPOINT}
es: ${LOCALSTACK_ENDPOINT}
firehose: ${LOCALSTACK_ENDPOINT}
glacier: ${LOCALSTACK_ENDPOINT}
glue: ${LOCALSTACK_ENDPOINT}
iam: ${LOCALSTACK_ENDPOINT}
iot: ${LOCALSTACK_ENDPOINT}
kafka: ${LOCALSTACK_ENDPOINT}
kinesis: ${LOCALSTACK_ENDPOINT}
kinesisanalytics: ${LOCALSTACK_ENDPOINT}
kms: ${LOCALSTACK_ENDPOINT}
lambda: ${LOCALSTACK_ENDPOINT}
mediastore: ${LOCALSTACK_ENDPOINT}
neptune: ${LOCALSTACK_ENDPOINT}
organizations: ${LOCALSTACK_ENDPOINT}
qldb: ${LOCALSTACK_ENDPOINT}
rds: ${LOCALSTACK_ENDPOINT}
redshift: ${LOCALSTACK_ENDPOINT}
route53: ${LOCALSTACK_ENDPOINT}
s3: ${LOCALSTACK_ENDPOINT}
sagemaker: ${LOCALSTACK_ENDPOINT}
secretsmanager: ${LOCALSTACK_ENDPOINT}
servicediscovery: ${LOCALSTACK_ENDPOINT}
ses: ${LOCALSTACK_ENDPOINT}
sns: ${LOCALSTACK_ENDPOINT}
sqs: ${LOCALSTACK_ENDPOINT}
ssm: ${LOCALSTACK_ENDPOINT}
stepfunctions: ${LOCALSTACK_ENDPOINT}
sts: ${LOCALSTACK_ENDPOINT}
swf: ${LOCALSTACK_ENDPOINT}
transfer: ${LOCALSTACK_ENDPOINT}
xray: ${LOCALSTACK_ENDPOINT}
aws:region: us-east-1
aws:s3ForcePathStyle: true
aws:secretKey: test
aws:skipCredentialsValidation: true
aws:skipRequestingAccountId: true
cloud:provider: aws
_END_
echo "Created ${STACK_CONFIG_FILE} file"
printf "Add the following to your shell profile and use \e[0;37mawslocal\e[0m as the AWS CLI command:\n\e[0;37malias awslocal=\"aws --endpoint-url ${LOCALSTACK_ENDPOINT}\"\e[0m\n"
# source this, e.g:
# . ./localstack-helpers.sh
LOCALSTACK_ENDPOINT=http://localhost:4566
alias awslocal="aws --endpoint-url ${LOCALSTACK_ENDPOINT}"
localstack-restapi-url() {
# e.g.: `curl $(localstack-api-url my-function) --data '{"foo":"bar"}'`
local function=$1;
local stage=${2:-stage};
local restapi_id=$(awslocal apigateway get-rest-apis | jq '.items' | grep -B1 "\"name\": \"${function}\"" | head -1 | grep -Eo '[a-z0-9]+' | tail -1);
echo ${LOCALSTACK_ENDPOINT}/restapis/${restapi_id}/${stage}/_user_request_/${function}
}
@delitescere
Copy link
Author

This is in response to pulumi/examples#185 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment