Caso de uso:
Exporte la lista de instantáneas en un archivo txt (old_snapshots.txt) al depósito S3. Desde Jenkins, use el comando aws cp para copiar el archivo al directorio /tmp/de Jenkins
--dry-run did not show any error
Sin embargo, cuando se pasa la siguiente línea bash con el comando aws eliminar en Jenkins, muestra ÉXITO, al mismo tiempo dice que se produjo un error y las instantáneas no se eliminan.
## actual deletion
file="/tmp/old_snapshots.txt"
while read delete_data
do
aws ec2 --region eu-west-1 delete-snapshot --snapshot-id $file
echo "Deleting snapshot $delete_data"
done <"$file"
Producción
An error occurred (InvalidParameterValue) when calling the DeleteSnapshot operation: Value (/tmp/old_snapshots.txt) for parameter snapshotId is invalid. Expected: 'snap-...'.
Deleting snapshot snap-xxxx81xxxxxx7fxxx
An error occurred (InvalidParameterValue) when calling the DeleteSnapshot operation: Value (/tmp/old_snapshots.txt) for parameter snapshotId is invalid. Expected: 'snap-...'.
Deleting snapshot snap-xxxacc49xxxxxxc26
An error occurred (InvalidParameterValue) when calling the DeleteSnapshot operation: Value (/tmp/old_snapshots.txt) for parameter snapshotId is invalid. Expected: 'snap-...'.
Deleting snapshot snap-04xxxxxxxx3fa3cxxxxxxf4
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
Finished: SUCCESS
Pedido:¿Este error An error occurred (InvalidParameterValue) when calling the DeleteSnapshot operation
parece demasiado genérico? ¿Alguien ha experimentado algún problema? Además, hice una prueba manual para eliminar solo una instantánea con AWS CLI agregando manualmente la identificación de la instantánea en Jenkins y eso funciona bien. Cualquier sugerencia será muy apreciada.
Incluyendo el comando aws
aws ec2 --region eu-west-1 delete-snapshot --snapshot-id snap-01x1618xxxxxxa51x
Found snapshotid: snap-01x1618xxxxxxa51x in the uploaded file: /tmp/old_snapshots.txt
Now deleting snapshot id snap-01x1618xxxxxxa51x
Respuesta1
Necesitas cambiar un poco tu guión.
$ sh abc.sh
What is in delete_data snap-xxxx81xxxxxx7fxxx
What is in file /tmp/old_snapshots.txt
Deleting snapshot snap-xxxx81xxxxxx7fxxx
What is in delete_data snap-xxxacc49xxxxxxc26
What is in file /tmp/old_snapshots.txt
Deleting snapshot snap-xxxacc49xxxxxxc26
What is in delete_data snap-04xxxxxxxx3fa3cxxxxxxf4
What is in file /tmp/old_snapshots.txt
Deleting snapshot snap-04xxxxxxxx3fa3cxxxxxxf4
$ cat abc.sh
## actual deletion
file="/tmp/old_snapshots.txt"
while read delete_data
do
#aws ec2 --region eu-west-1 delete-snapshot --snapshot-id $file
echo "What is in delete_data $delete_data"
echo "What is in file $file"
echo "Deleting snapshot $delete_data"
done < $file
La variable de llamada de su secuencia de comandos file
es constante, pero debe pasar el contenido del archivo línea por línea. Entonces, reemplace a continuación
aws ec2 --region eu-west-1 delete-snapshot --snapshot-id $file
Con
aws ec2 --region eu-west-1 delete-snapshot --snapshot-id $delete_data
Respuesta2
Para beneficio de otros usuarios de la comunidad, utilicé la --debug
bandera para descubrir que '\r'
se estaban agregando caracteres adicionales alquebrar-#
Salida de depuración
2020-01-28 18:09:02,295 - MainThread - botocore.hooks - DEBUG - Event load-cli-arg.ec2.delete-snapshot.snapshot-id: calling handler <awscli.paramfile.URIArgumentHandler object at >
2020-01-28 18:09:02,296 - MainThread - botocore.hooks - DEBUG - Event process-cli-arg.ec2.delete-snapshot: calling handler <awscli.argprocess.ParamShorthandParser object at >
2020-01-28 18:09:02,296 - MainThread - awscli.arguments - DEBUG - Unpacked value of u'snap-0xxxxxxxxxxxxxxxx\r' for parameter "snapshot_id": u'snap-0xxxxxxxxxxxxxxxx\r'
Para resolver el problema: pasé tr -d '\r'
a la variable que contiene el valor para iniciar la conversación.
Ejemplo:
tr -d '\r' < input > output
Guión actualizado
file="/tmp/old_snapshots.txt"
cat $file | tr -d '\r' | while read -r line;
do
aws ec2 --region eu-west-1 delete-snapshot --snapshot-id $line
done