Moto. AWS na-akwa emo

Nnwale bụ akụkụ dị mkpa nke usoro mmepe. Na mgbe ụfọdụ ndị mmepe kwesịrị ịgba ọsọ ule na mpaghara, tupu ime mgbanwe.
Ọ bụrụ na ngwa na-eji Amazon Web Services, eke oba akwukwo Moto zuru oke maka nke a.
Moto. AWS na-akwa emo

Enwere ike ịhụ ndepụta zuru oke nke mkpuchi akụrụngwa ebe a.
Enwere ntụgharị na Github Hugo Picado - moto-ihe nkesa. Foto dị njikere, malite na ojiji. Naanị nuance bụ na mgbe mmalite, mba AWS emebebeghi ihe ndi ozo ebe ahu.

Ọfọn, nke ahụ dị mfe iji dozie ya.

Ebe ọ bụ na ịmalite, ịkwesịrị ịkọwa ụdị ọrụ ahụ (ihe ruru mgbanwe MOTO_SERVICE), naanị anyị ga-akọwa ihe okike nke akụ.

Ka anyị gbanwee ya ntakịrị ibido.sh:

Kama nke

moto_server $MOTO_SERVICE -H $MOTO_HOST -p $MOTO_PORT

Fanye:

if [ -f /opt/init/bootstrap.py ]; then
  moto_server $MOTO_SERVICE -H $MOTO_HOST -p $MOTO_PORT & (sleep 5 && echo "Executing bootstrap script." && python /opt/init/bootstrap.py)
else
  moto_server $MOTO_SERVICE -H $MOTO_HOST -p $MOTO_PORT
fi
wait

Faịlụ ikpeazụ bụ:

ibido.sh

#!/bin/sh

# validate required input
if [ -z "$MOTO_SERVICE" ]; then
  echo "Please define AWS service to run with Moto Server (e.g. s3, ec2, etc)"
  exit 1
fi

# setting defaults for optional input
if [ -z "$MOTO_HOST" ]; then
  MOTO_HOST="0.0.0.0"
fi

if [ -z "$MOTO_PORT" ]; then
  MOTO_PORT="5000"
fi

echo "Starting service $MOTO_SERVICE at $MOTO_HOST:$MOTO_PORT"

if [ -f /opt/init/bootstrap.py ]; then
  moto_server $MOTO_SERVICE -H $MOTO_HOST -p $MOTO_PORT & (sleep 5 && echo "Executing bootstrap script." && python /opt/init/bootstrap.py)
else
  moto_server $MOTO_SERVICE -H $MOTO_HOST -p $MOTO_PORT
fi
# Prevent container from exiting when bootstrap.py finishing
wait

Anyị na-ewu ihe oyiyi ọhụrụ ma tinye ya n'ime ndekọ anyị.

Ọzọ, ka anyị dee edemede mmalite akụrụngwa, dịka ọmụmaatụ ngalaba SWF, iji ụlọ akwụkwọ maka ịrụ ọrụ na AWS - boto3:

bootstrap_swf.py

import boto3
from botocore.exceptions import ClientError
import os

os.environ["AWS_ACCESS_KEY_ID"] = "fake"
os.environ["AWS_SECRET_ACCESS_KEY"] = "fake"

client = boto3.client('swf', region_name='us-west-2', endpoint_url='http://localhost:5000')

try:
    client.register_domain(
        name='test-swf-mock-domain',
        description="Test SWF domain",
        workflowExecutionRetentionPeriodInDays="10"
    )
except ClientError as e:
    print "Domain already exists: ", e.response.get("Error", {}).get("Code")

response = client.list_domains(
    registrationStatus='REGISTERED',
    maximumPageSize=123,
    reverseOrder=True|False
)

print 'Ready'

Ezi uche bụ nke a:

  • Mgbe ịmalite, anyị na-ebuli edemede anyị /opt/init/bootstrap.py.
  • Ọ bụrụ na etinyere faịlụ ahụ, a ga-eme ya.
  • Ọ bụrụ na enweghị faịlụ, ihe nkesa efu moto ga-amalite naanị.

Na, ị nwere ike ịkwa emo niile akụ site na ịmalite otu akpa:

docker run --name swf -d 
    -e MOTO_SERVICE=swf 
    -e MOTO_HOST=0.0.0.0 
    -e MOTO_PORT=5000 
    -p 5001:5000 
    -v /tmp/bootstrap_swf.py:/opt/init/bootstrap.py 
    -i awesome-repo.com/moto-server:latest

Ka anyị nwaa ya na mmekọrịta:

Moto. AWS na-akwa emo

Ọ na-arụ ọrụ!

Yabụ na anyị nwere ike ịme docker-compose.yml, nke ga-echekwa mgbanwe nnwale oge:

docker-compose.yml

version: '3'
services:
  s3:
    image: picadoh/motocker
    environment:
      - MOTO_SERVICE=s3
      - MOTO_HOST=10.0.1.2
    ports:
      - "5002:5000"
    networks:
      motonet:
        ipv4_address: 10.0.1.2
    volumes:
      - /tmp/bootstrap_s3.py:/opt/init/bootstrap.py
  swf:
    image: picadoh/motocker
    environment:
      - MOTO_SERVICE=swf
      - MOTO_HOST=10.0.1.3
    ports:
      - "5001:5000"
    networks:
      motonet:
        ipv4_address: 10.0.1.3
    volumes:
      - /tmp/bootstrap_swf.py:/opt/init/bootstrap.py
  ec2:
    image: picadoh/motocker
    environment:
      - MOTO_SERVICE=ec2
      - MOTO_HOST=10.0.1.4
    ports:
      - "5003:5000"
    networks:
      motonet:
        ipv4_address: 10.0.1.4
    volumes:
      - /tmp/bootstrap_ec2.py:/opt/init/bootstrap.py
networks:                             
  motonet:                          
    driver: bridge                
    ipam:                         
      config:                       
        - subnet: 10.0.0.0/16

N'ezie, enwere ike iji usoro a ọ bụghị naanị na laptọọpụ onye nrụpụta. Nnwale mbụ na ịkwa emo mgbe mgbakọ gachara ga-enyere aka iwepụ nsogbu ndị nwere ike ime mgbe ị na-agba ọsọ na gburugburu dev *.

Ntughari:

Motocker repo - github.com/picadoh/motocker
Moto repo - github.com/spulec/moto
Akwụkwọ Boto3 - boto3.amazonaws.com/v1/documentation/api/latest/index.html

isi: www.habr.com

Zụta nnabata ntụkwasị obi maka saịtị nwere nchekwa DDoS, sava VPS VDS 🔥 Zụta ebe nrụọrụ weebụ a pụrụ ịtụkwasị obi na nchekwa DDoS, sava VPS VDS | ProHoster